繁体   English   中英

WPF Datagrid数据绑定DataView

[英]WPF Datagrid DataBinding DataView

预先警告 WPF的新人在这里:

我有一个绑定到DataTable的DefaultView的DataGrid

ResultDataGrid.ItemsSource = resultTable.DefaultView;    

我知道列名,如果另一列是1 (总是0或1),则需要更改列的前景

目前我有:

private void ResultDataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
        if (e.Column.Header.ToString() == "columnName")
        {
            e.Column.CellStyle = FindResource("columnStyle") as Style;
        }
}

在XAML中:

<Window.Resources>
    <Style TargetType="DataGridCell" x:Key="columnStyle">
        <Setter Property="Foreground" Value="Black"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding resultTable, Path={StaticResource otherColumnName}}" Value="1">
                <Setter Property="Foreground" Value="Red"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

在构造函数中设置了otherColumnName的位置

public ResultsCustom(DataTable resultclass, CustomQuery query)
{
    // Some other stuff
    this.Resources.Add("otherColumnName", COLUMN_NAME);
}

XAML样式似乎没有正确的路径,将不胜感激!

我不确定这行代码:

Path={StaticResource otherColumnName}

您是否要比较resultTable的属性“ otherColumnName”以查看其是否为1? 这不是静态资源,您可以将绑定更改为:

Path=otherColumnName

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM