【问题标题】:WPF: ItemsControl.Resources Setter - binding to element's contentWPF:ItemsControl.Resources Setter - 绑定到元素的内容
【发布时间】:2018-07-21 12:07:17
【问题描述】:
<ItemsControl>
    <ItemsControl.Resources>
        <Style TargetType="{x:Type RadioButton}">
            <Setter Property="Command" Value="{Binding MyCommand}"/>
            <Setter Property="CommandParameter" Value="{Binding RelativeSource={Problem}, Path=Content}"/>
        </Style>
    </ItemsControl.Resources>

    <RadioButton Content="1"/>
    <RadioButton Content="2"/>
    <RadioButton Content="3"/>
    <RadioButton Content="4"/>
    <RadioButton Content="5"/>
    <RadioButton Content="6"/>
</ItemsControl>

我想将每个 RadioButton 的 CommandParameter 设置为其内容。 我应该使用哪个 RelativeSource?

【问题讨论】:

    标签: c# wpf binding itemscontrol


    【解决方案1】:

    我认为没有设置RelativeSource 是正确的。但如果不是,您可以尝试以下构造 - RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type RadioButton}}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      相关资源
      最近更新 更多