Hello, if the parent's datasource has a child property that is a collection (let's say it is called ChildCollection) is there a trick to reference it?
So, this code sample is basically what I am attempting to do. But when I use this approach I do not get any data to my child controls.
<UserControl>
<UserControl.Resources>
<sample:Data x:Key="MyData" />
</UserControl.Resources>
<Canvas DataContext="{StaticResource MyData}">
<TextBlock Text="{Binding Title}" />
<My:UserControl DataContext="{Binding ChildCollection}" />
</Canvas>
</UserControl>
My dependency property looks like this:
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register("Data", typeof(IEnumerable), typeof(ButtonList),
new UIPropertyMetadata(new PropertyChangedCallback(DataChanged)));
public DoubleCollection Data
{
get { return (DoubleCollection)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
static void DataChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
(sender as FrameworkElement).DataContext = e.NewValue;
}
public void SetData(IEnumerable data)
{
(View as CollectionViewSource).Source = data;
}
Thank you in advance for your help.