c#
[ValueConversion(typeof(bool), typeof(System.Windows.FontStyles))]
public class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool reValue = System.Convert.ToBoolean(value);
if (reValue == true)
{
return System.Windows.FontStyles.Italic;
}
else return System.Windows.FontStyles.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (FontStyle)value == FontStyles.Italic;
}
}
wpf
引用
<Window.Resources>
<local:DateConverter1 x:Key="dateConverter"/>
</Window.Resources>
绑定
<CheckBox Name="IsIalic" Content="倾斜" />
<TextBox FontStyle="{Binding ElementName=IsIalic, Path=IsChecked, Converter={StaticResource dateConverter}, Mode=TwoWay}"/>