문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top