与ConverterParameter绑定的WPF Tag按钮

时间:2016-10-11 14:39:13

标签: c# wpf xaml data-binding binding

我有一个Button,其Tag取决于布尔变量。 我实现了Binding如下:

Tag="{Binding LiveInProgress, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, 
      Converter={StaticResource BoolToPathConverter}, Mode=OneWay, 
      ConverterParameter=cross.svg|play.svg}"

Converter如下:

public class BoolToPathConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var parameterString = parameter as string;
            if (parameterString.IsNullOrEmpty()) return "";

            var parameters = parameterString.Split(new char[]{ '|'});
            if ((bool) value)
                return parameters[0];

            return parameters[1];
        }

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

问题在于我看不到任何标签。你有什么主意吗?谢谢!

0 个答案:

没有答案