开发者

WPF RibbonButton: LargeImageSource and Label not updated via DataTriggers

开发者 https://www.devze.com 2023-04-04 11:36 出处:网络
I\'m puzzled by a peculiar phenomenon in RibbonButton\'s behavior. Everything works fine when I set the LargeImageSource and the Labe开发者_运维技巧l statically in XAML:

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

Everything works fine when I set the LargeImageSource and the Labe开发者_运维技巧l 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消