Question

I have a custom class which a usercontrol has implemented as a dependency property in it's code behind.

public partial class HandControl
{
    public HandControl()
    {
        InitializeComponent();
    }

    public Seat Seat
    {
        get
        {
            return (Seat)GetValue(SeatProperty);
        }
        set
        {
            SetValue(SeatProperty, value);
        }
    }

    public static readonly DependencyProperty SeatProperty = DependencyProperty.Register("Seat", typeof(Seat), typeof(HandControl), new PropertyMetadata(null));
}

In my case I've bound the name property in that class to a label inside the usercontrols xaml.

<Label Content="{Binding Seat.Player.Name, RelativeSource={RelativeSource AncestorType={x:Type controls:HandControl}}}"/>

The view model of my window contains the property SeatTl and the xaml is binding to it:

    public Seat SeatTr
    {
        get { return _seatTr; }
        private set
        {
            _seatTr = value;
            OnPropertyChanged();
        }
    }

    <customControls:HandControl Grid.Row="1"
                                Grid.Column="3"
                                Seat="{Binding SeatTr}" />

However, when I change my class content (the name property) and manually raise OnPropertyChanged in my viewmodel (not the usercontrol), the label is not updated and still has the same content.

    private void OnSeatChanged(Player player, SeatPosition seatPosition)
    {
        //... doing the changes ...\\
        OnPropertyChanged("SeatTr");
    }

Whats my problem? Anyone got a clue?

Was it helpful?

Solution

I think u should raise OnPropertyChanged for Seat.Player.Name property as It is being chaged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top