依赖属性的数据触发器绑定

时间:2018-10-10 01:09:35

标签: c# wpf dependency-properties datatrigger

<ControlTemplate.Triggers>
    <DataTrigger Binding="{Binding ElementName=Switcher, Path=On}" Value="True">
        <DataTrigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="SliderOnBody" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.3" />
                    <ThicknessAnimation To="35 5 5 5" Duration="0:0:0.3" Storyboard.TargetName="Slider" Storyboard.TargetProperty="Margin"/>
                </Storyboard>
            </BeginStoryboard>
         </DataTrigger.EnterActions>
             <DataTrigger.ExitActions>
                 <BeginStoryboard>
                     <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="SliderOnBody" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.3" />
                        <ThicknessAnimation To="5 5 5 5" Duration="0:0:0.3" Storyboard.TargetName="Slider" Storyboard.TargetProperty="Margin"/>
                     </Storyboard>
                 </BeginStoryboard>
        </DataTrigger.ExitActions>
    </DataTrigger>
</ControlTemplate.Triggers>

我有这个简单的XAML代码,它使用名为“ Switcher”的控件的依赖属性“ On”,但我无法使用它。编译器不会通知我任何错误。但是,当我运行应用程序并更改属性的值时,动画不会触发!

1 个答案:

答案 0 :(得分:0)

由于克莱门斯的建议,我发现了问题。我错误地定义了依赖项属性。我将其设置为正常含义:      公共布尔组; },同时正确定义了依赖项属性和事件……