gpt4 book ai didi

c# - RibbonGroup 的 ItemContainerStyle

转载 作者:太空宇宙 更新时间:2023-11-03 16:15:46 25 4
gpt4 key购买 nike

我正在尝试使用以下 xaml 将一个 RibbonGroup 和几个 RibbonButton 绑定(bind)到我的 View 模型:

<Style TargetType="{x:Type ribbon:RibbonGroup}" x:Key="RibbonGroupStyle">
<Setter Property="Header" Value="{Binding Header}" />
<Setter Property="ItemContainerStyle" Value="{DynamicResource RibbonButtonStyle}" />
<Setter Property="ItemsSource" Value="{Binding Buttons}" />
</Style>

<Style TargetType="{x:Type ribbon:RibbonButton}" x:Key="RibbonButtonStyle">
<Setter Property="Label" Value="{Binding Header}" />
</Style>

这给了我以下错误,我可以理解,但是如何正确地将 RibbonButton 的标签绑定(bind)到我的 View 模型?

A style intended for type 'RibbonButton' cannot be applied to type 'RibbonControl'.

最佳答案

您可以将一种样式放在另一种样式中并将其应用于每个按钮:

<Style TargetType="{x:Type ribbon:RibbonGroup}" x:Key="RibbonGroupStyle">
<Style.Resources>
<Style TargetType="{x:Type ribbon:RibbonButton}" BasedOn="{StaticResource {x:Type ribbon:RibbonButton}">
<Setter Property="Label" Value="{Binding Header}" />
</Style>
</Style.Resources>

<Setter Property="Header" Value="{Binding Header}" />
<Setter Property="ItemsSource" Value="{Binding Buttons}" />
</Style>

关于c# - RibbonGroup 的 ItemContainerStyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15878871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com