WPF RibbonButton: LargeImageSource and Label not updated via DataTriggers

安稳与你 提交于 2019-12-11 18:51:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7408609/wpf-ribbonbutton-largeimagesource-and-label-not-updated-via-datatriggers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!