我正在开发一个需要检查某些可用性属性的小应用程序。我正在使用WPF的用户界面。如果从组合框中进行选择,我需要更改一些前景色。我有这样的DataTemplate:布尔转换器在WPF中的多个绑定
<DataTemplate x:Key="userTemplate">
<TextBlock VerticalAlignment="Center">
<Image Source="imgsource.png" Height="25" Width="25" />
<Run Text="{Binding BooleanObjectName}" Foreground="{Binding boolobject, Converter={StaticResource convAvailability}}"/>
</TextBlock>
所以我用这个皈依一个的IValueConverter那台色到前景:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
BooleanObject boolobject = (BooleanObject)value;
if (boolobject.IsBoolValueOne) return System.Drawing.Brushes.Green;
else if (boolobject.IsBoolValueTwo) return System.Drawing.Brushes.Red;
else if (boolobject.IsBoolValueThree) return (SolidColorBrush)(new BrushConverter().ConvertFrom("#d3d300"));
else return System.Drawing.Brushes.Black;
}
什么是错,因为在我界面我总是得到黑色。对此有何想法?
任何帮助将非常感激。 在此先感谢。
你需要一个[刷子](https://msdn.microsoft.com/en-us /library/system.windows.media.brushes(v=vs.110).aspx)从WPF项目中的System.Windows.Media命名空间中获取,System.Drawing命名空间用于WinForms。 – Funk
你的Convert方法被调用了吗? – mm8
@ mm8我试过调试,我认为它没有被调用 – R3muSGFX