WPF RibbonButton:LargeImageSource 和 Label 未通过 DataTriggers 更新

发布于 2024-12-04 23:21:50 字数 2069 浏览 2 评论 0原文

我对 RibbonButton 行为中的一个特殊现象感到困惑。

当我在 XAML 中静态设置 LargeImageSource 和 Label 时,一切正常:

<ribbon:RibbonButton x:Name="ButtonArchive"
                     LargeImageSource="..\Assets\archive_insert.png"
                     Label="{Binding Path=ItemArchiveButton, 
                     Source={StaticResource Strings}}"/>

但是当我尝试通过 DataTriggers 修改这些属性时 - 似乎没有发生任何事情。 触发器确实起作用了;我可以看到其他属性 - 例如 Command 或 IsEnabled - 在同一触发器中设置确定。也只是这些...

这是 XAML:

<ribbon:RibbonButton x:Name="ButtonArchive"
    LargeImageSource="..\Assets\archive_insert.png"
    Label="{Binding Path=ItemArchiveButton, Source={StaticResource Strings}}">
    <ribbon:RibbonButton.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding ="{Binding ElementName=ItemsList, Path=SelectedItem.IsArchived}" Value="false">
                    <Setter Property="ribbon:RibbonButton.Command" Value="{Binding ArchiveItemCommand}" />
                    <Setter Property="ribbon:RibbonButton.LargeImageSource" Value="..\Assets\archive_insert.png" />
                    <Setter Property="ribbon:RibbonButton.Label" Value="{Binding Path=ItemArchiveButton, Source={StaticResource Strings}}" />
                </DataTrigger>
                <DataTrigger Binding ="{Binding ElementName=ItemsList, Path=SelectedItem.IsArchived}" Value="true">
                    <Setter Property="ribbon:RibbonButton.Command" Value="{Binding RestoreItemCommand}" />
                    <Setter Property="ribbon:RibbonButton.LargeImageSource" Value="..\Assets\archive_extract.png" />
                    <Setter Property="ribbon:RibbonButton.Label" Value="{Binding Path=ItemRestoreButton, Source={StaticResource Strings}}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ribbon:RibbonButton.Style>
</ribbon:RibbonButton>

设置命令在这两种情况下都可以正常工作,但其他 2 个属性则不然...

欢迎任何建议。

I'm puzzled by a peculiar phenomenon in RibbonButton's behavior.

Everything works fine when I set the LargeImageSource and the Label statically in XAML:

<ribbon:RibbonButton x:Name="ButtonArchive"
                     LargeImageSource="..\Assets\archive_insert.png"
                     Label="{Binding Path=ItemArchiveButton, 
                     Source={StaticResource Strings}}"/>

But when I try to modify these properties via DataTriggers - nothing seems to be happening.
The triggers do work; I can see the other properties - like Command or IsEnabled - set OK in the same trigger. It's just these too...

Here's the XAML:

<ribbon:RibbonButton x:Name="ButtonArchive"
    LargeImageSource="..\Assets\archive_insert.png"
    Label="{Binding Path=ItemArchiveButton, Source={StaticResource Strings}}">
    <ribbon:RibbonButton.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding ="{Binding ElementName=ItemsList, Path=SelectedItem.IsArchived}" Value="false">
                    <Setter Property="ribbon:RibbonButton.Command" Value="{Binding ArchiveItemCommand}" />
                    <Setter Property="ribbon:RibbonButton.LargeImageSource" Value="..\Assets\archive_insert.png" />
                    <Setter Property="ribbon:RibbonButton.Label" Value="{Binding Path=ItemArchiveButton, Source={StaticResource Strings}}" />
                </DataTrigger>
                <DataTrigger Binding ="{Binding ElementName=ItemsList, Path=SelectedItem.IsArchived}" Value="true">
                    <Setter Property="ribbon:RibbonButton.Command" Value="{Binding RestoreItemCommand}" />
                    <Setter Property="ribbon:RibbonButton.LargeImageSource" Value="..\Assets\archive_extract.png" />
                    <Setter Property="ribbon:RibbonButton.Label" Value="{Binding Path=ItemRestoreButton, Source={StaticResource Strings}}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ribbon:RibbonButton.Style>
</ribbon:RibbonButton>

Setting the Command works fine in the both conditions, but not the other 2 properties...

Any advice will be welcome.

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

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

发布评论

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

评论(1

淡写薰衣草的香 2024-12-11 23:21:50

我在MSDN论坛上问了同样的问题,我得到的答案确实解决了这个问题。

问题是您在按钮本身中设置 LargeImageSource 和 Label 的属性。当你这样做时,它会优先于你的风格触发因素。我建议在样式中使用设置器来设置默认值,并删除按钮的属性设置。

I asked the same question at the MSDN forum, and the answer I've got really solved this.

The problem is your setting properties for LargeImageSource and Label in the button itself. When you do this it takes precidence over your style triggers. I suggest using setters in the style to set your defaults, and remove the property settings it the button.

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