你可以使用
ConverterParameter
从一个转换器接收它们
<TextBlock Foreground="{x:Bind FirstNameError,Mode=OneWay,Converter={StaticResource ErrorToFont},ConverterParameter=foreground}"
FontStyle="{x:Bind FirstNameError,Mode=OneWay,Converter={StaticResource ErrorToFont},ConverterParameter=fontstyle}"
FontWeight="{x:Bind FirstNameError,Mode=OneWay,Converter={StaticResource ErrorToFont},ConverterParameter=fontweight}">
//转换器
public class ErrorFontConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (parameter.ToString() == "fontstyle")
return (bool)value ? Windows.UI.Text.FontStyle.Italic : Windows.UI.Text.FontStyle.Normal;
else if (parameter.ToString() == "foreground")
return (bool)value ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Blue);
else
return (bool)value ? FontWeights.Bold : FontWeights.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}