It had to happen, if you rant about something, WPF in my case, it will come back to bite you.

The story begins with my evaluation of Xceed’s datagrid. They have an express version which is free, it is nearly feature complete and can be used for commercial software. There is also a paid for version that adds some whiz and a couple of nice to haves like 3D views and Office 2007 Themes but I am impressed with their courage to release so much for free. I am happy with it so far and will probably buy it to get the themes.

I installed the express version and replaced the Toolkit DataGrid I have been using in next to no time. This is when the power or WPF and proper separation of concerns shine. I literally deleted the old grid, dropped the new grid in, let Resharper do its thing with the namespaces and I was ready to roll! Or almost… I was back to square one on the background highlighting I lost so much time with. After losing another couple of hours trying to highlight the background of cells with certain values I threw in the towel and asked the question in Xceed’s newsgroups. And I got an answer! And what is more I got the WPF-ish correct answer that solved the problem and demonstrated that I was really going to great lengths to ignore the obvious solution: use a style for the type, the DataCell type in this case.

<Style TargetType=”xcdg:DataCell”>
    <Style.Triggers>
        <Trigger Property=”Content”>
            <Trigger.Value>
                <System:Double>1.0</System: Double >
            </Trigger.Value>
            <Setter Property=”Background” Value=”Red” />
        </Trigger>
    </Style.Triggers>
</Style>

Kudos to the Xceed support team for solving the problem.

 I tried this method with the Toolkit DataGrid but could not make it work anyone with a solution?

Advertisements