开发者

WPF DataGrid RowDataBound?

开发者 https://www.devze.com 2023-01-02 19:12 出处:网络
Ok this is driving me mad, I feel like a total Newbie. I\'m using WPF\'s DataGrid control from WPF Toolkit with .NET 3.5.

Ok this is driving me mad, I feel like a total Newbie.

I'm using WPF's DataGrid control from WPF Toolkit with .NET 3.5.

Link on Codeplex here

I w开发者_JAVA技巧ant an equivalent to the classic GridView's RowDataBound event, and I can't find any. I tried working with LoadingRow, but it fires every time I scroll.

I'm trying to change the background color of certain cells in my grid based on a database values.

I'm new to WPF. Should I be using the XAML binding?


The apt way of doing that in WPF is through Datatrigger

<DataTrigger Binding="{Binding Path=State}" Value="WA">
    <Setter Property="Foreground" Value="Red" />
</DataTrigger>  

that comprehends to

UPDATE DataGrid
SET Foreground = 'Red'
WHERE State = 'WA';


I ended up disabling row virtualization on the DataGrid using EnableRowVirtualization="False". That way, the LoadingRow event would fire only once for all items.

0

精彩评论

暂无评论...
验证码 换一张
取 消