0

I have bound the Text property of a TextBlock in my UserControl to one of its dependency properties (DPs), and the initial binding works properly and the text is displayed. However, when the FrameRate property is updated later on, the change is not reflected in the TextBlock.

Here is the code for the binding in the UserControl:

<UserControl>
...
        <TextBlock Text="{Binding UiView.FrameRate, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
...
</UserControl>

    public UiView UiView
    {
        get => (UiView)GetValue(s_uiViewProperty);
        set => SetValue(s_uiViewProperty, value);
    }

    public static readonly DependencyProperty s_uiViewProperty = DependencyProperty.Register(
        nameof(UiView), typeof(UiView), typeof(UiViewPanel), new PropertyMetadata(OnUiViewPropertyChanged));

And here is the code for the FrameRate property, which is defined in the UiView class:

private readonly FrameRate m_frameRate = new FrameRate();

public double FrameRate => m_frameRate.Current;

I am sure that the FrameRate property is being updated, but the change is not reflected in the TextBlock. How can I fix this issue and ensure that the updated value of FrameRate is reflected in the TextBlock?

Vahid
  • 5,144
  • 13
  • 70
  • 146
  • 1
    You're binding to a property of the object you have as a dependency property. That property needs to notify change. Either by being a dp itself or using inotifypropertychanged. – Andy May 18 '19 at 20:05
  • @Andy Thanks Andy, DP seems to work. I am not sure how inotifypropertychanged can be implemented in this case as DataContext comes from the parent of the user control – Vahid May 18 '19 at 20:08

0 Answers0