WPF RibbonButton:LargeImageSource 和 Label 未通过 DataTriggers 更新 [英] WPF RibbonButton: LargeImageSource and Label not updated via DataTriggers
问题描述
我对 RibbonButton 行为中的一个奇特现象感到困惑.
I'm puzzled by a peculiar phenomenon in RibbonButton's behavior.
当我在 XAML 中静态设置 LargeImageSource 和 Label 时,一切正常:
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}}"/>
但是当我尝试通过 DataTriggers 修改这些属性时 - 似乎什么也没发生.触发器确实有效;我可以看到其他属性 - 如 Command 或 IsEnabled - 在同一个触发器中设置为 OK.也只有这些了...
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...
这是 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 个属性则不行...
Setting the Command works fine in the both conditions, but not the other 2 properties...
欢迎提出任何建议.
推荐答案
我在 MSDN 论坛上问过同样的问题,我得到的答案确实解决了这个问题.
I asked the same question at the MSDN forum, and the answer I've got really solved this.
问题在于您在按钮本身中为 LargeImageSource 和 Label 设置的属性.当你这样做时,它优先于你的风格触发器.我建议在样式中使用 setter 来设置默认值,并删除按钮的属性设置.
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.
这篇关于WPF RibbonButton:LargeImageSource 和 Label 未通过 DataTriggers 更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!