none
wpf toolkit datagrid如何设置背景色? RRS feed

答案

  • 你可以得到你的DataGridRow,然后改变,比如在loadingrow 事件里面:

    private void DataGrid_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
            {
                Persons RowDataContaxt = e.Row.DataContext as Persons;
                if (RowDataContaxt != null)
                {
                    if (RowDataContaxt.Sales == 50)
                        e.Row.Background = FindResource("RedBackgroundBrush") as Brush;
                    else if (RowDataContaxt.Sales == 60)
                        e.Row.Background = FindResource("GreenBackgroundBrush") as Brush;
                }
            }

    或者在xaml里面用style:

     <Style.Triggers> 
                <DataTrigger Binding="{Binding Sales}" Value="90"> 
                    <Setter Property="Background" Value="{StaticResource RedBackgroundBrush}"/> 
                </DataTrigger> 
                <DataTrigger Binding="{Binding Sales}" Value="80"> 
                    <Setter Property="Background" Value="{StaticResource GreenBackgroundBrush}"/> 
                </DataTrigger> 
            </Style.Triggers> 


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2012年10月31日 11:32
    版主

全部回复

  • 还是喜winform的那个dagagrid,可以手动添加行,可以手动设置任一单元格的值,字体,颜色等等

    2012年10月30日 1:49
  • 你可以得到你的DataGridRow,然后改变,比如在loadingrow 事件里面:

    private void DataGrid_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
            {
                Persons RowDataContaxt = e.Row.DataContext as Persons;
                if (RowDataContaxt != null)
                {
                    if (RowDataContaxt.Sales == 50)
                        e.Row.Background = FindResource("RedBackgroundBrush") as Brush;
                    else if (RowDataContaxt.Sales == 60)
                        e.Row.Background = FindResource("GreenBackgroundBrush") as Brush;
                }
            }

    或者在xaml里面用style:

     <Style.Triggers> 
                <DataTrigger Binding="{Binding Sales}" Value="90"> 
                    <Setter Property="Background" Value="{StaticResource RedBackgroundBrush}"/> 
                </DataTrigger> 
                <DataTrigger Binding="{Binding Sales}" Value="80"> 
                    <Setter Property="Background" Value="{StaticResource GreenBackgroundBrush}"/> 
                </DataTrigger> 
            </Style.Triggers> 


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2012年10月31日 11:32
    版主