我有一个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();
}
}
问题在于我看不到任何标签。你有什么主意吗?谢谢!