IsChecked 的触发器未触发

发布于 2024-12-12 09:50:25 字数 1322 浏览 0 评论 0原文

我想更改 ToggleButton 的图标(Fluent RibbonBar 的内容),具体取决于它的 IsChecked 属性。现在我编写了以下样式片段:

<Fluent:ToggleButton.Style>
    <Style BasedOn="{StaticResource RibbonButtonStyle}" TargetType="{x:Type Fluent:ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Fluent:ToggleButton}}, Path=IsChecked}" Value="False">
                <Setter Property="Icon" Value="{StaticResource ResourceKey=Style.Images.Pined}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Fluent:ToggleButton}}, Path=IsChecked}" Value="True">
                <Setter Property="Icon" Value="{StaticResource ResourceKey=Style.Images.Unpined}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Fluent:ToggleButton.Style>

问题是触发器不能很好地加载图像。问题不在于 IsChecked 本身没有实现,我已经对此进行了测试。而且我也没有在其他地方设置图标属性。如果我在其他地方使用图像资源,它们也可以正常工作。

重建信息:我已将 ToggleButton 放入 Backstage,作为放置在 BackstageTabItem 中的 RibbonListBox 的 DataTemplate。

I want to change the Icon of a ToggleButton (Content of Fluent RibbonBar) Depending on it's IsChecked Property. Now I have written the following style snippet:

<Fluent:ToggleButton.Style>
    <Style BasedOn="{StaticResource RibbonButtonStyle}" TargetType="{x:Type Fluent:ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Fluent:ToggleButton}}, Path=IsChecked}" Value="False">
                <Setter Property="Icon" Value="{StaticResource ResourceKey=Style.Images.Pined}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Fluent:ToggleButton}}, Path=IsChecked}" Value="True">
                <Setter Property="Icon" Value="{StaticResource ResourceKey=Style.Images.Unpined}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Fluent:ToggleButton.Style>

The problem is that the Trigger doesn't load the Image well. The problem is not, that IsChecked doesn't actualize itself, I've already tested this. And also I don't set the icon property anywhere else. The image resources also works fine if I use them otherwhere.

Information for Rebuild: I've put the ToggleButton into the Backstage as the DataTemplate of a RibbonListBox placed in a BackstageTabItem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌能量女王 2024-12-19 09:50:26

由于这是切换按钮的样式,因此您不需要 findancestor 绑定 - 您可以使用 self.实际上,由于 IsChecked 是一个 DP,您只需使用触发器 - 例如

Since this is a style for togglebutton you don't need a findancestor binding - you would use self. And actually since IsChecked is a DP you can just use a trigger - eg <Trigger Property="IsChecked" Value="False">

江南烟雨〆相思醉 2024-12-19 09:50:26

绝对需要从控件声明中删除Icon属性,因为它将覆盖样式尝试执行的所有操作,因为优先级

但是这些DataTriggers将不起作用,绑定将寻找一个祖先,本身被排除,因此您必须更改它们以及AndrewS已经指出的那样。只有满足这两个条件,您才有机会使其发挥作用(尽管甚至可能存在其他干扰)。

You absolutely need to remove the Icon property from the control declaration as it will override everything a style tries to do due to precedence.

But those DataTriggers will not work, the binding will look for an ancestor, itself excluded, so you must change them as well as already pointed out by AndrewS. Only if both conditions are met you have a chance of getting this to work (there may be even additional interferences though).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文