将UserControl中的属性绑定到其依赖项属性之一的问题

时间:2019-05-18 19:40:11

标签: c# wpf data-binding user-controls dependency-properties

我已将UserControl中的TextBlock的Text属性绑定到其DP的属性之一。初始绑定有效,我看到显示了文本!但是稍后,当FrameRate属性更新时,它不会在TextBlock中更新!

if(file==input){skip}

背后的代码:

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

在UiView类内部定义FrameRate属性,如下所示:

    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));

我确定它会更新。

0 个答案:

没有答案