Silverlight 5 中多边形填充属性绑定中的 ValueConverter
我正在尝试使用 ValueConverter 将 Fill 属性绑定到 ModelView 中的 bool 属性 IsBottomSelected
这里是我的多边形 xaml:
<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 中未触发。
I'm trying to bind Fill property to bool property IsBottomSelected in ModelView using ValueConverter
Here my 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>
and this is 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;
}
}
The same code is working in WPF, in Silverlight 5 ValueConverter not fired.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论