solid brush property not binding

亡梦爱人 提交于 2019-12-20 06:58:40

问题


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>

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

The value that I put to brush it like this:

this.Color = new SolidBrush(color);

color is a variable that contains any color


回答1:


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

You have to use SolidColorBrush instead of SolidBrush.



来源:https://stackoverflow.com/questions/14703979/solid-brush-property-not-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!