牢固的画笔属性不具有约束力 [英] solid brush property not binding

查看:95
本文介绍了牢固的画笔属性不具有约束力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有X班,有一些数据:

I have a class X there are some data:

private string yyy;

public string YYY
{
    get { return yyy; }
    set
    {
        yyy= value;
        NotifyPropertyChanged("YYY");
    }
}

private SolidBrush color;

public SolidBrush Color
{
    get { return color; }
    set
    {
        color= value;
        NotifyPropertyChanged("Color");
    }
}

我的数据网格像这样绑定到此类:

My Data Grid bind to this class like this:

<DataGrid x:Name="dg1" ItemsSource="{Binding}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTemplateColumn Header="yyy" >
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding YYY}" Foreground="{Binding Color}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
</DataGrid>

当我执行Foreground ="Red"时,它可以工作,但是在绑定时却不起作用,为什么?

When I do Foreground="Red" it works but with the binding it does not work, why?

我这样刷的值:

this.Color = new SolidBrush(color);

color是包含任何颜色的变量

color is a variable that contains any color

推荐答案

看起来您很困惑 System.Drawing.SolidBrush ,它不是WPF的一部分.

Looks like you are confusing System.Windows.Media.SolidColorBrush with System.Drawing.SolidBrush, which is not part of WPF.

您必须使用SolidColorBrush而不是SolidBrush.

这篇关于牢固的画笔属性不具有约束力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆