gpt4 book ai didi

wpf - 如何通过 xaml 更改动态资源值(例如触发器)

转载 作者:行者123 更新时间:2023-12-05 08:02:03 26 4
gpt4 key购买 nike

例如,我有一个元素样式和我想更改特定资源的触发器

<Style x:Key="MyStyle" TargetType="{x:Type Tree:MyListBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding Property}" Value="ItemSelected">
<Setter Property="MydinamicResourceKey" Value="NewValue"/>
</DataTrigger>
</Style.Triggers>
</Style>

这可能吗?

最佳答案

也许尝试使用 VisualStateManager?

这是来自 Microsoft's ListBox Styles and Templates page 的想法

<Style x:Key="MyStyle" TargeType="{x:Type Tree:MyListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Tree:MyListBox}">
<Border x:Name="Border">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="myUIElementName"
Storyboard.TargetProperty="myUIElementProperty">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{DynamicResource MyResourceKey}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
.... more code here....
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

我有一个 tutorial by Shawn Wildermuth bookmarked关于这种类型的动画/变化 - 我仍然经常引用它。

希望这对您有所帮助,可以让您朝着正确的方向前进。

关于wpf - 如何通过 xaml 更改动态资源值(例如触发器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10410370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com