【发布时间】:2015-05-04 13:01:59
【问题描述】:
我在屏幕上收集了一系列错误,一个错误一行。用户可以通过单击该行上的按钮来关闭任何错误消息。代码示例:
<UserControl>
<ItemsControl ItemsSource="{Binding Errors}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid x:Name="grid" Height="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding ErrorText}"/>
<Button Grid.Column="1" Width="16" Height="16" Content="Close" Command="{Binding DataContext.RemoveErrorCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" CommandParameter="{Binding CurrentError}">
<Button.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click">
<BeginStoryboard>
<Storyboard TargetProperty="Height" TargetName="grid">
<DoubleAnimation To="0" Duration="0:0:0.35"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>
出了什么问题:如您所见,我添加了带有情节提要的触发器以使其清楚,我想顺利隐藏消息,并且只有在关闭它之后。因此,首先是情节提要,然后执行命令。如何实现?请尽量减少代码隐藏。
【问题讨论】:
-
这个答案应该为您指明正确的方向:stackoverflow.com/a/14124760/1231132 您可以保留现有的 Button 触发器,并添加一个额外的交互触发器来调用您的命令。