How can I stretch ExpandableFieldRecordPresenter vertically such that it will occupy whole width of XamDataGrid.
I was unable to find any property in XamDataGrid but by using Snoop utility I've found that I need to set HorizontalAlignment=Stretch on ExpandableFieldRecordPresenter and on ancestor element named PART_NestedContentSite, on the latter I also had to set Grid.ColumnSpan=3.
I am currently using attached property with changed handler that walks visual tree and does what is needed but it's a hack.
Code of my hack:
public static readonly DependencyProperty NestedContentHorizontalAlignmentProperty = DependencyProperty.RegisterAttached("NestedContentHorizontalAlignment", typeof (HorizontalAlignment), typeof (XamDataGridHelper), new PropertyMetadata(default(HorizontalAlignment), OnNestedContentHorizontalAlignmentChanged)); private static void OnNestedContentHorizontalAlignmentChanged(DependencyObject d, DependencyPropertyChangedEventArgs ev) { var presenter = (ExpandableFieldRecordPresenter) d; var newValue = (HorizontalAlignment) ev.NewValue; presenter.SetCurrentValue(FrameworkElement.HorizontalAlignmentProperty, newValue); var parent = VisualTreeHelper.GetParent(d); while (parent != null) { var parentFE = parent as FrameworkElement; if (parentFE != null && parentFE.Name == "PART_NestedContentSite") { // XXX this will break if style will change significantly var grid = VisualTreeHelper.GetParent(parentFE) as Grid; Debug.Assert(grid != null, "Incompatible style template of XamDataGrid"); if (grid != null) { parentFE.SetCurrentValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); parentFE.SetCurrentValue(Grid.ColumnSpanProperty, 3); grid.Dispatcher.BeginInvoke(new Action(grid.InvalidateMeasure), DispatcherPriority.Background); } return; } parent = VisualTreeHelper.GetParent(parent); } Debug.Fail("Could not set NestedContentHorizontalAlignment on XamDataGrid, incompatible style template"); } public static void SetNestedContentHorizontalAlignment(ExpandableFieldRecordPresenter element, HorizontalAlignment value) { element.SetValue(NestedContentHorizontalAlignmentProperty, value); } public static HorizontalAlignment GetNestedContentHorizontalAlignment(ExpandableFieldRecordPresenter element) { return (HorizontalAlignment)element.GetValue(NestedContentHorizontalAlignmentProperty); }
Hi,
Instead of using code behind and the visual tree helper the other approach is to re-template the style. In this case you would copy the ExpandableFieldRecordPresenter style from the DataPresenterGeneric_Express.xaml file in the DefaultStyles folder into your application and make the modifications you need there.
Let me know if you have any questions.
I have submitted a new product idea for you with the details that you provided for a built-in method to stretch the ExpandableFieldRecordPresenter so that it occupies the whole width of the xamDataGrid, directly to our Product Management team. And I described the two method that we had already pursued.
Our product team chooses new feature requests for development based on popular feedback from our customer base. Infragistics continues to monitor application development for all of our products so as trends appear in requested features, we can plan accordingly.
We value your input, and our philosophy is to enhance our toolset based on customer feedback. If your features are chosen for development you will be notified at that time. Your reference number is PI12040052.
If you need any further assistance please do not hesitate to ask.
Thanks, that confirms my suspicion that there is no built-in way to do this. Unfortunately copying styles is not a good solution (too much maintenance burden).