I have UserControl
, lets call it as CustomDataGrid
, that contains DataGrid
. Remained content doesn't matter. SelectedItem
property of DataGrid
must be SelectedItem
property of CustomDataGrid
. And I wanna be able to use Binding
with this property, cause I use MVVM
pattern. So I have to declare SelectedItem
as DependencyProperty
in CustomDataGrid
. But I have no ideas haw can I make it properly...
This is how DepedencyProperty
-s is declared usually:
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(
"SelectedItem", typeof(Object), typeof(CustomDataGrid),
new FrameworkPropertyMetadata(default(Object), SelectedItemPropertyCallback)
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
// Optionally
private static void SelectedItemPropertyCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
// dataGrid - `DataGrid` nested in `UserControl`
((CustomDataGrid)obj).dataGrid.SelectedItem = e.NewValue;
}
// Obviously, it has no any link with nested `dataGrid`. This is the problem.
public Object SelectedItem
{
get { return GetValue(SelectedItemProperty); }
set { SetValue(SelectedItemProperty, value); }
}
So, how can I declare SelectedItem
property correctly?