Hi, My WPF UserControl knowledge is like an hour old. So please forgive me if there are plenty of tutorials or/and answers on SO regarding this question (To be honest I
You can add a new dependency property to your custom usercontrol and bind your datagrid items source to that property. Make sure to handle selection changed event on your user control's data grid and set the dependency property to the selected item.
public object MySelectedItem
{
get { return (object)GetValue(MySelectedItemProperty); }
set { SetValue(MySelectedItemProperty, value); }
}
// Using a DependencyProperty as the backing store for MySelectedItem. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MySelectedItemProperty =
DependencyProperty.Register("MySelectedItem", typeof(object), typeof(YOURUSERCONTROLTYPE), new UIPropertyMetadata(null));
handle the selection changed event
public YourUserControl()
{
InitializeComponent();
dgv.SelectionChanged += dgv_SelectionChanged;
}
void dgv_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MySelectedItem = dgv.SelectedItem;
}
and then bind to
ItemsSource="{Binding ElementName=myUserControl, Path=MySelectedItem.CustomerOrders}"