我正在尝试使用ValueConverter将Fill属性绑定到ModelView中的bool属性IsBottomSelected
这是我的xaml for polygon:
<Polygon Name="h_bottom" Points="50,50 0,100 100,100 50,50" Stroke="Green" StrokeThickness="3" MouseLeftButtonDown="h_bottom_MouseDown" >
<Polygon.Fill>
<Binding Path="IsBottomSelected">
<Binding.Converter>
<view:BoolToColorConverter/>
</Binding.Converter>
</Binding>
</Polygon.Fill>
</Polygon>
这是ValueConverter:
public class BoolToColorConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
if (Convert.ToBoolean(value.ToString())) return new SolidColorBrush(Colors.Cyan);
}
catch { }
return new SolidColorBrush(Colors.White);
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
相同的代码在WPF中工作,在Silverlight 5中没有触发ValueConverter。