I have a ListView to display attachments and each attachment has a delete button. When I change the ItemSource for the list (i.e. when viewing another item that has different attachments), the icon for the delete button no longer draws.
我有一个ListView来显示附件,每个附件都有一个delete按钮。当我更改列表的ItemSource时(例如,当查看另一个具有不同附件的项目时),delete按钮的图标将不再绘制。
Here's the template
这是模板
<DataTemplate x:Key="attachmentListData">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0">
<TextBlock TextTrimming="CharacterEllipsis" Text="{Binding Path=filename}" TextDecorations="{Binding Path=deleted, Converter={StaticResource deletedStrikethroughConverter}}" />
</Label>
<Button Grid.Column="1" Visibility="{Binding Path=deleted, Converter={StaticResource attachmentDeleteButtonVisibilityConverter}}" Style="{DynamicResource MetroCircleButtonStyle}" Width="40" Height="40" Click="onDeleteAttachmentClicked">
<Rectangle Fill="Black" Width="15" Height="15">
<Rectangle.OpacityMask>
<VisualBrush Visual="{StaticResource appbar_close}" Stretch="Fill" />
</Rectangle.OpacityMask>
</Rectangle>
</Button>
</Grid>
</DataTemplate>
I've been able to work around the issue by having the appbar_close icon drawn somewhere else in the screen, but having the visibility set to hidden. If the icon isn't somewhere else in the screen, after I change the ItemSource the icon will stop drawing.
我可以通过在屏幕的其他地方绘制appbar_close图标来解决这个问题,但是要将可视性设置为隐藏。如果图标不在屏幕的其他位置,在我更改ItemSource后,图标将停止绘图。
Obviously this workaround is hacky, but what is the better way to ensure that the icon still shows up?
显然,这个解决方案很容易出错,但是有什么更好的方法可以确保图标仍然显示?
2 个解决方案
#1
0
I think you are missing the DataType property on the DataTemplate. http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.datatype.aspx. I'd be surprised if this was not giving you a binding error on the line where you're binding button Visibility.
我认为您丢失了DataTemplate上的DataType属性。http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.datatype.aspx。如果没有在绑定按钮可见性的行上给您一个绑定错误,我将会感到惊讶。
#2
0
You can set x:Shared=False in appbar_close and also you should use PresentationOptions:Freeze, RenderOptions for performance.
您可以在appbar_close中设置x:Shared=False,还应该使用PresentationOptions:Freeze, RenderOptions来实现性能。
Hope it helps.
希望它可以帮助。
#1
0
I think you are missing the DataType property on the DataTemplate. http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.datatype.aspx. I'd be surprised if this was not giving you a binding error on the line where you're binding button Visibility.
我认为您丢失了DataTemplate上的DataType属性。http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.datatype.aspx。如果没有在绑定按钮可见性的行上给您一个绑定错误,我将会感到惊讶。
#2
0
You can set x:Shared=False in appbar_close and also you should use PresentationOptions:Freeze, RenderOptions for performance.
您可以在appbar_close中设置x:Shared=False,还应该使用PresentationOptions:Freeze, RenderOptions来实现性能。
Hope it helps.
希望它可以帮助。