【问题标题】:How Do I pass the parent control Tag value to the ParameterConverter [duplicate]如何将父控件标记值传递给 ParameterConverter [重复]
【发布时间】:2021-10-19 19:18:12
【问题描述】:

像下面的 xaml 示例一样,将静态值传递给 ConverterParameter 似乎很常见。

有没有办法将父控件的Tag属性传递给它?

<StackPanel Margin="{StaticResource XSmallTopMargin}" Tag="abc">
    <RadioButton GroupName="AppTheme" dt:DesignTime.Content="Light"
        Checked="ThemeChanged_CheckedAsync" 
        IsChecked="{x:Bind ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Light, Mode=OneWay}">
    </RadioButton>
</StackPanel>

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    你不能。至少我不知道。它需要您绑定它,并且无法将任何东西绑定到 ConverterParameter。 x:StaticStaticResource 是将某些东西传递给 ConverterParameter 的好方法。但是Binding 不行

    但是你可以做的也是让你的转换器也支持IMultiValueConverter,然后在MultiBinding中传递父标签。

    我可能要宰了你的绑定,但大致是这样的。

    <RadioButton GroupName="AppTheme" dt:DesignTime.Content="Light"
        Checked="ThemeChanged_CheckedAsync" >
        <RadioButton.IsChecked>
            <MultiBinding  Converter="{StaticResource EnumToBooleanConverter}">
                <Binding Source="{x:Bind ElementTheme}"/>
                <Binding RelativeSource="{RelativeSource Self}" Path="Tag"/>
            </MultiBinding>           
        </RadioButton.IsChecked>
    </RadioButton>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-07
      • 2019-01-04
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      • 2019-08-12
      相关资源
      最近更新 更多