开发者

Setting MultiBinding on WPF DataGrid Column

开发者 https://www.devze.com 2023-03-02 11:54 出处:网络
I\'m trying to style a WPF DataGrid so that when a property changes from the previous row there is a visual indicator.To start, just by changing the foreground color.However, when I do this, the bindi

I'm trying to style a WPF DataGrid so that when a property changes from the previous row there is a visual indicator. To start, just by changing the foreground color. However, when I do this, the bindings in my multivalue converter are broken. It seems really odd, because the binding works just fine for the contents of the column. So in the example below, the location value is shown, but the multivalue converter is receiving DependencyProperty.Unset for each value being passed in. Does anybody have any ideas as to 开发者_Python百科what I'm doing wrong?

<DataGridTextColumn Header="Location" Binding="{Binding Location}">
    <DataGridTextColumn.Foreground>
        <MultiBinding Converter="{StaticResource ResourceKey=valueEqualityToBrush}">
           <Binding Path="Location" />
           <Binding Path="Location" RelativeSource="{RelativeSource Mode=PreviousData}" />
        </MultiBinding>
    </DataGridTextColumn.Foreground>
</DataGridTextColumn>

Thanks, Greg


You probably have this error in the Output window:

System.Windows.Data Error: 36 : Cannot find previous element for use as RelativeSource because there is no parent in generated context.

This obviously means binding has no way of finding the sibling because there is no parent. I do not know if there is any workaround for this sadly...


DataGridColumns don't bind to properties other than the cell contents because they aren't part of the element tree. There's a workaround presented here: http://blogs.infragistics.com/blogs/josh_smith/archive/2008/06/26/data-binding-the-isvisible-property-of-contextualtabgroup.aspx

Just use DataContextSpy and you'll be good to go.

0

精彩评论

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

关注公众号