I recently redefined the WPF DevXpress grid to provide me with the SelectedObject property, with which I can access from my loosely coupled ViewModel.
I created the SelectedObject dependency property and bound it to OneWayToSource in my XAML.
Everthing works fine, but if I try to do this ReadOnly (for completeness), I get a compilation error and say that I cannot bind to the ReadOnly property. In the compilation code below, I turned on (but rem'd out) the bits that I tried in an attempt to get the ReadOnly property.
Can anyone help?
The dependency property of my overridden control looks like this:
//public static readonly DependencyPropertyKey SelectedRowKey = DependencyProperty.RegisterReadOnly("SelectedObject", typeof(object), typeof(MyGrid), new PropertyMetadata(null)); //public static readonly DependencyProperty SelectedObjectProperty = SelectedRowKey.DependencyProperty; public readonly static DependencyProperty SelectedObjectProperty = DependencyProperty.Register("SelectedObject", typeof(object), typeof(MyGrid), new PropertyMetadata(null)); public object SelectedObject { get { return GetValue(SelectedObjectProperty); } set { throw new NotImplementedException(); } }
XAML:
<StackPanel> <devxgrid:MyGrid AutoPopulateColumns="True" DataSource="{Binding Animals}" SelectedObject="{Binding MyObject, Mode=OneWayToSource}" Width="300" Height="300"> <devxgrid:MyGrid.View> <MyGrid:TableView AllowEditing="False" Name="GridView" AutoWidth="True" /> </devxgrid:MyGrid.View> </devxgrid:MyGrid> </StackPanel>
wpf mvvm binding dependency-properties
Andy clarke
source share