Scratching my brain here....
I have the following ListBox
<ListBox Height="221" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Top" Width="Auto" ItemsSource="{Binding MediaItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True">
<my:MediaItemControl CurrentItem="{Binding}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
The listbox is bound to an ObservableCollection of a object.
As you can see this ListBox includes a user control. Within the user control I have the following dependancy property information.
public static readonly DependencyProperty CurrentItemProperty = DependencyProperty.Register("CurrentItem", typeof(TypedMediaItem), typeof(MediaItemControl), new PropertyMetadata(null));
public TypedMediaItem CurrentItem
{
get { return (TypedMediaItem)GetValue(MediaItemControl.CurrentItemProperty); }
set {
SetValue(MediaItemControl.CurrentItemProperty, value);
}
}
What I am trying to do is pass the current item within the ItemsSource of the ListBox, to my usercontrol. However using the above methods doesnt work, the setter on the dependency property is never called.
What am I doing wrong?
MediaItems
is anObservableCollection<TypedMediaItem>
and you are sure that theIemsSource
binding is correctly bound to the collection. Is this correct? Also, how do you know the dependency property's setter is never called?(Be specific) – Bryan Watts