UserControl Binding only working in constructor

I'm trying to bind a UserControl to a property in my code. The binding works in the constructor, but as I try to assign another value to the property after pressing a button, the UserControl does not change it's value.


<UserControl Content="{Binding MainDock, UpdateSourceTrigger=PropertyChanged}"/>  

The binded property:

public UserControl MainDock { get; set; }


public DBControl()

  this.DataContext = this;

  MarkerControl mc = new MarkerControl();
  MainDock = mc;

Button method:

private void ShowItemsToPrint(object sender, RoutedEventArgs e)
  ItemsToPrintControl sitp = new ItemsToPrintControl();
  MainDock = sitp;

1 answer

  • answered 2021-05-04 13:57 Wellerman

    You need to be calling OnPropertyChanged():

    public class MyObject : INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        private UserControl _MainDock;
        public UserControl MainDock
            get { return _MainDock; }
                _MainDock = value;
        protected void OnPropertyChanged(string name)
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));