Silverlight 5 中多边形填充属性绑定中的 ValueConverter

发布于 2025-01-04 12:30:40 字数 1210 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文