So I know that I can put multiple fieldlayout nodes in my XAML and then, programmatically, change which one is used in the AssigningFieldLayoutToItem event. But what I'd like to do is something a little more databinding-y.
Is there any way that I could create a property on my underlying object (serving as the DataContext of the window) that is either a FieldLayout object or a collection of Field objects and use databinding to hook up the grid's fieldlayout to that property?
That would certainly be a far more flexible approach. Let me know if anyone out there has any ideas.
HI,
The FieldLayout is not an actual visual element in the visual tree. This fact will prevent you from binding to it.
Sincerely, MattDeveloper Support Engineer
Hello,
You could use an attached property that you can bind to the XamDataGrid, which will handle the rest automatically. Here is what I am suggesting :
public static ObservableCollection <FieldLayout > GetAttachedFieldLayouts(DependencyObject obj)
{
return (ObservableCollection <FieldLayout >)obj.GetValue(AttachedFieldLayoutsProperty);
}
public static void SetAttachedFieldLayouts(DependencyObject obj, ObservableCollection <FieldLayout > value)
obj.SetValue(AttachedFieldLayoutsProperty, value);
public static readonly DependencyProperty AttachedFieldLayoutsProperty =
DependencyProperty .RegisterAttached("AttachedFieldLayouts" ,
typeof (ObservableCollection <FieldLayout >),
typeof (FieldLayoutAdvisor ),
new UIPropertyMetadata (null , new PropertyChangedCallback (OnAttachedFieldLayoutsChanged)));
private static void OnAttachedFieldLayoutsChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
DataPresenterBase dpb = o as DataPresenterBase ;
if (dpb != null )
if (dpb.FieldLayoutSettings == null )
dpb.FieldLayoutSettings = new FieldLayoutSettings ();
dpb.FieldLayoutSettings.AutoGenerateFields = false ;
ObservableCollection <FieldLayout > collection = args.NewValue as ObservableCollection <FieldLayout >;
if (collection != null && collection.Count > 0)
dpb.FieldLayouts.Clear();
foreach (FieldLayout fl in collection)
dpb.FieldLayouts.Add(fl);
Then, you can bind the XamDataGrid to your DataContext :
<igDP:XamDataGrid
Name="xamDataGrid1"
DataSource="{Binding Path=Source}"
fla:FieldLayoutAdvisor.AttachedFieldLayouts="{Binding FieldLayouts}"/>