【发布时间】:2019-02-13 13:57:13
【问题描述】:
让我们假设有一个Control 和一个默认的Style,我只能基于或覆盖它。在这个Style 中有一个ControlTemplate,它有另一个Control,并直接设置DependencyProperty 的Value。
类似这样的:
<Style TargetType="{x:Type ParentControl}" x:Key="Test">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ParentControl}">
<ChildControl Property="Value" ... />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在我想更改ChildControl 中Property 的Value,而不访问/更改默认Style。
如果我没记错的话,ChildControl 的 Foreground 不能被简单的 Style-Setter 覆盖,因为 Value Precedence。
<!-- Doesen't Work -->
<Style TargetType="{x:type ChildControl}">
<Setter Property="Property" Value="Value"/>
</Style>
但根据相同的来源,可以用Animation 覆盖它(如果动画永远持续)。
就在那里,我被困住了。更准确地说:我不能在ScrollViewer 中覆盖垂直ScrollBar-Track 的IsDirectionReversed Property。
<ScrollViewer Height="300" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ScrollViewer.Resources>
<Style TargetType="{x:Type Track}">
<Style.Triggers>
<Trigger Property="IsVisible" Value="True">
<Trigger.EnterActions>
<BeginStoryboard x:Name="SetValue">
<Storyboard Storyboard.TargetProperty="(Track.IsDirectionReversed)">
<BooleanAnimationUsingKeyFrames RepeatBehavior="Forever" Duration="24:00:00">
<DiscreteBooleanKeyFrame Value="False" KeyTime="00:00:00"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<StopStoryboard BeginStoryboardName="SetValue"/>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
</ScrollViewer.Resources>
<Rectangle Height="800"/>
</ScrollViewer>
Trigger/Animation 有问题吗?或者当IsDirectionReversed-Property 通过Animation 设置时Track-Control 的行为不会改变?
【问题讨论】:
标签: c# wpf xaml .net-4.6.1