Associate DataFactory to its Usercontrol

Grids for WPF Forum

Posted 12 years ago by Moondance
Avatar
My xaml looks somewhat like :

<UserControl x:Name ="MyUserControl" >
......
<PropertyGrid x:Name="MyPropertyGrid"
SelectedObjects="{Binding Path=MyItems}"
....
<PropertyGrid.DataFactory>
<MyDataFactory/>
</PropertyGrid.DataFactory>

</UserControl>

I have a class (MyDataFactory) derived from DataFactory.
In my MyDataFactory I want to have a variable that points to the usercontrol "MyUserControl" or, better, its DataContext.
How can I pass this information to my class? Through a constructor?
Help is appreciated.

Comments (3)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Yes, you would have to do that in the code-behind constructor of MyUserControl, which would probably look like:
public MyUserControl() {
    InitializeComponent();

    this.MyPropertyGrid.DataFactory = new MyDataFactory(/* Pass what you want here */);
}


Actipro Software Support

Posted 12 years ago by Moondance
Avatar
Well the thing is that I have to keep things in xaml and cannot have a parameterized constructor. Can I set maybe the DataFactoryOptions in xaml? Is that possible?
Thanks
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

No, it is not possible to set the DataFactoryOptions as that is generated dynamically by the PropertyGrid and/or its items. I don't believe you'd be able to do it purely from XAML, as the DataFactory is independent of the visual tree.

You could build a custom PropertyGrid class (i.e. MyPropertyGrid) that sets it's own DataFactory based on a custom dependency property. That approach is effectively the same as the one suggested before, but is more encapsulated.


Actipro Software Support

The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.