OK,
I have a data template for items:
<DataTemplate x:Key="SmallDayEventItemTemplate">
<Border ...>
<Grid ...>
<TextBlock ...
Text="{Binding Path=Title}"/>
<my:SmallPlayer ...
PlayerSource="{Binding Path=MediaSource}">
</my:SmallPlayer>
</Grid>
</Border>
</DataTemplate>
Also i have a UserControl named SmallPlayer.
In SmallPlayer.xaml.cs:
public Uri PlayerSource
{
get { return (Uri)GetValue(PlayerSourceProperty); }
set
{
SetValue(PlayerSourceProperty, value);
//player.Open(value);
}
}
public static readonly DependencyProperty PlayerSourceProperty =
DependencyProperty.Register("PlayerSource", typeof(Uri), typeof(SmallPlayer));
So when i feed MediaSource of an item inside owner window code, item‘s set accessor gets called but, SmallPlayer‘s PlayerSource‘s set accessor never gets called! This is while TextBlock which is bind to Title property acts as expected!
Uri uri = null;
if (Uri.TryCreate(mediaName, UriKind.RelativeOrAbsolute, out uri))
item.MediaSource = uri;
It make me confuse! What’s wrong?
The CLR wrapper for a dependency property is never guaranteed to be called, so should never contain any extraneous logic. If you need extra logic when the dependency property is changed, use dependency property metadata. And specifically, the property changed callback.