【发布时间】:2012-03-02 02:48:57
【问题描述】:
我有以下数据触发器,但退出操作没有触发。输入动作工作发现。我还尝试将 Binding 转换为布尔值,以查看它是否与 null 有关,但这也无济于事。我有什么问题,为什么我的退出操作没有在这里触发?
<DataTrigger Binding="{Binding }" Value="{x:Null}">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To=".5" From="0" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" From=".5" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
编辑:这里肯定发生了一些奇怪的事情,因为我也尝试过将故事板排除在等式之外并只使用 Setters——现在什么都没有发生......
所以,代替这个,我将发布整个 TextBlock,也许有人可以指出我错过了什么
<Grid DataContext="{Binding ElementName=ConfigTree, Path=SelectedItem.Details}">
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Padding="10" VerticalAlignment="Center" FontWeight="Bold" FontSize="14" Opacity="0">
Select a configuration on the right to modify its selected columns
<TextBlock.Style>
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
<Style.Triggers>
<DataTrigger Binding="{Binding }" Value="{x:Null}">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard Duration="0:0:1">
<DoubleAnimation Storyboard.TargetProperty="Opacity" To=".5" From="0" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" From=".5" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
ConfigTree 是一个树视图,SelectedItem.Details 是一个实现 observablecollection 和 INotifyPropertyChanged 的类。我已经检查了调试器,这个绑定正在正确更新,并且在我的实例值和空值之间来回切换。
【问题讨论】:
-
顺便说一句,我已经确认绑定确实在正确更新。正如我所期望的那样,绑定来回更改为空值-但没有退出操作:(
标签: wpf xaml storyboard datatrigger