Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top