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.
Hold off on that though...I had tried going back to the ColumnLayout from the TemplateColumnLayout approach. Let me try it first with the TemplateColumnLayout and embedded XamGrid and see if that works first...Thank You!
No, I'm afraid I can't convert it to a TemplateColumnLayout. No matter what I do, I get the following error:
Error: Unhandled Error in Silverlight Application Code: 4004
Category: ManagedRuntimeError
Message: System.InvalidOperationException: MeasureOverride of element 'Infragistics.Controls.Grids.Primitives.ColumnLayoutTemplateRowCellsPanel' should not return PositiveInfinity or NaN as its DesiredSize. at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
I've tried removing all references to styles in my xaml (which I shouldn't have to do) and I still get the error. When I do a concept application, I do not get the error.
At this point, I'm about done with investing in this issue. I am simply going to mark it down as not feasible. Thanks for your time!
I've found the solution for your issue in Silverlight. The right way was to create the custom x:Type markup, as you found in this post. You were really close to solving it. I think the best way for you to see it, is by downloading the sample I've attached. It's just a simple SL application where such functionality is achieved (even using a converter). Please, download it, examine it, and if you need some help or if you have any questions, you know we'll be glad to help. :)
Yes, that's exactly what I did. I tried it again, and I was still getting the error. Because I appreciated your good attitude and there was an example app, I went ahead and took another go at troubleshooting the error I was getting when using the TemplateColumnLayout.
As I stated before, I was getting the following error:
I thought these had something to do with my styling, but alas it was a bug in the version of Infragistics that I'm using (and I have no power to get our team to upgrade at this time :X). The bug is that if you do not explicitly set the height and width of the grid (i.e. if you let the grid stretch to its container), then it throws that error. Maybe this has been fixed in future versions, but in my version this bug exists.
So, I'm taking the minor hit of being forced to explicitly state the height and width in exchange for the cool (and really necessary) styling.
Thanks for your perseverance Martin. Much props to you and your team.
-Bill Raiford
Hi Bill,
I'm happy to hear that this worked our for you. This was a really interesting case that you had. You also did a great job investigating it, and finally we both got to the result needed. Thanks for that. Now, other users may benefit from this as well. And if you have any other questions, I'll be happy to help again.
Thanks again,