是否可以通过WPF中的转换器将属性绑定到自身?

时间:2017-09-29 18:09:36

标签: c# wpf xaml binding ivalueconverter

我需要在触发器上更改属性的值,我需要根据现有值和某个参数来实现。所以,我试图像这样使用xaml:

<Style.Triggers>
    <Trigger ...>
        <Setter Property="BorderBrush" 
                Value="{Binding Path=BorderBrush, 
                RelativeSource={RelativeSource Self},
                Converter={StaticResource MyConverter},
                ConverterParameter=ParamValue}" />
    </Trigger>
</Style.Triggers>

转换器很简单:

[ValueConversion(typeof(SolidColorBrush), typeof(SolidColorBrush))]
public class MyConverter : IValueConverter
{
    public object Convert(object existingValue, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        //change the brush
    }

    public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

但是,使用此类代码,MyConverter.Convert()中的existingValue参数为null。

那么,有没有办法使用自己的值将转换器应用于属性?我无法将其作为ConverterParameter传递,因为它用于转换器所需的其他数据。

0 个答案:

没有答案