Hi,
My situation is that for displaying fields in XamDataGrid, I have AutoGenerateFields="True" and then I collapse the fields in FieldLayoutInitialized event which I don't need. And then also in FieldLayoutInitialized event I have also set CellVisibilityWhenGrouped = Visibility.Collapsed with one of the field (lets call this field A ). I am also displaying another field (lets call this field B in the same column as field A but in 2nd row having field A in first row.)
Now what I want to do is since field A's CellVisibilityWhenGrouped = Visibility.Collapsed, its collapsed when grouped but field B in same column still remains visible. How can I make field B collapsed as well when field A is collapsed when its grouped.
I tried binding field B's Visibility with field A's Visibility but it didn't work.
Binding bin = new Binding(); bin.Source = layout.Fields["A"]; bin.Path = new PropertyPath("Visibility"); BindingOperations.SetBinding(layout.Fields["B"], Field.VisibilityProperty, bin);
Your help will be much appreciated.
Thanks,
Imad.
Hello Imad,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Thanks for the solution, I was also planning to do something similar.
In that case you can use the following code in order to have everything works as you want:
bool isInGroup = false; foreach (var item in e.Groups) { if (item.FieldName == "A") { isInGroup = true; } } if (isInGroup) e.FieldLayout.Fields["B"].Visibility = System.Windows.Visibility.Collapsed; else e.FieldLayout.Fields["B"].Visibility = System.Windows.Visibility.Visible;
Hope this helps you.
This solution doesn't work as I need to set the visibility of field B again when field A ungrouped and becomes visible. So it won't work if field A is not last when field A is ungrouped. Infact when we ungroup field A, the e.Group collection no longer contains field A.
Hello,
I have been looking into your requirement and I suggest you add the following check and the code will execute only when you group Field “A”:
if(e.Groups.LastOrDefault().FieldName == "A") { e.FieldLayout.Fields["B"].Visibility = e.FieldLayout.Fields["A"].VisibilityResolved; }