Jalal
Jalal

Reputation: 6856

Problem in Binding a DependencyProperty into another one at XAML

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?

Upvotes: 0

Views: 353

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178820

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.

Upvotes: 2

Related Questions