Greetings!
I'm having a problem trying to bind a heirarchical column style to its parent row's DataContext in xaml.
My grid's datasource is a collection of ViewModels, each of which has a property MyProperty. I need to set a style on a border that is in a datatemplate inside of a TemplatedColumn in a ColumnLayout inside of the grid, according to that parent ViewModel.MyProperty value (with a converter of course). That's a lot of nesting!
Here is a sketch of my problem:
<ig:XamGrid ItemsSource="{Binding Path=ItemViewModels}">
...
<ig:ColumnLayout> <<<<<<child level in heirarchy
<ig:TemplateColumn Key="SomeColumn">
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{Binding RowData Path=MyProperty, Converter={StaticResource MyPropertyToBrushConverter}}"> //This does not work obviously, since I'm posting!
I'd appreciate any help you can give!
Hello William,
Thank you for your post. There is a quick solution for your issue - change the <ig:ColumnLayout> to <ig:TemplateColumnLayout> (since you are using <ig:TemplateColumn> inside). Also don't forget to set the "Key" property on the ig:TemplateColumnLayout. After doing that, all of the bindings should work fine.
You can refer to this sample for a quick demo on how to set it all up.
If that happens not to be your case, then you could share a samples and we'll be happy to help.
Thanks,
Martin Stoev
Hi Martin! Thanks for the quick reply.
Sadly, however, that does not quite meet my requirement. :X
It does however give me another way of describing my question. In that example that you pointed me to, there is a property called "Orders". That properties is a nested collection represented by another embedded "child" xamGrid. This grid exists for each individual RowData in the parent grid (Name="dataGrid"). This child xamGrid has the following column declared:
<ig:TextColumn Key="OrderDate" FormatString="{}{0:d}"> <ig:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding Path=XWG_Orders_OrderDateLabel, Source={StaticResource Strings}}" /> </DataTemplate> </ig:TextColumn.HeaderTemplate></ig:TextColumn>
My requirement is specifically getting a reference to the RowData of the parent xamGrid's(Name="dataGrid"). It would look something similar to the following:
<ig:TextColumn Key="OrderDate" FormatString="{}{0:d}"> <ig:TextColumn.HeaderTemplate> <DataTemplate> <Border BorderBrush="{Binding [MarkupWouldPointTo"dataGrid" RowData], Converter=MyConverter}"> <TextBlock Text="{Binding Path=XWG_Orders_OrderDateLabel, Source={StaticResource Strings}}" /> </Border> </DataTemplate> </ig:TextColumn.HeaderTemplate></ig:TextColumn>
Essentially, I am trying to change the border color in my data template based on data in the parent grid's RowData. In the above example, the analog would be trying to get a border around the OrderDate field, based on the parent grid's (Name="dataGrid") ContactName's value.
Does that help explain my question? As far as I can tell though, changing to TemplateColumnLayout does not address this specific issue. If it is not possible, then no big sweat I'll figure something else out. But it would seem to me that it should be possible to get a hold of the parent grid's row data through xaml.