1

我已从 WPF 应用程序中的 CLR 属性转移到依赖项属性。我有一个问题,以下代码位于我需要从各种其他视图模型访问的基类中。当它是 CLR 属性时,它是静态的,但现在不是,因此在未设置它的视图模型中始终返回 null。有办法解决这个问题吗?

    public Tuple<Guid, string> SelectedEntity
    {
        get { return (Tuple<Guid, string>)GetValue(SelectedEntityProperty); }
        set { SetValue(SelectedEntityProperty, value); }
    }

    public static readonly DependencyProperty SelectedEntityProperty =
        DependencyProperty.Register("SelectedEntity", typeof(Tuple<Guid, string>), typeof(MyViewModelBase), new PropertyMetadata(null));
4

0 回答 0