WPF MVVM OnProperty已更改,但未在其他视图模型上显示



伙计们。我正在实施一个 MVVM 代码。我正在使用福迪。我成功创建了BaseViewModel,它是:

using System.ComponentModel;
namespace GProject_MVVM.ViewModel
{
    /// <summary>
    /// A base view model that fires Property Changed events as needed
    /// </summary>
    public class BaseViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// The event that is fired when any child property changes its value
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
        /// <summary>
        /// Call this to fire <see cref="PropertyChanged"/> event
        /// </summary>
        /// <param name="name"></param>
        public void OnPropertyChanged(string name)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }
}

没有问题,但是当我在窗口视图模型上调用它时,我收到一个错误,即OnPropertyChanged未定义这是我的窗口视图模型

using System.Windows;
namespace GProject_MVVM.ViewModel
{
    /// <summary>
    /// THe View Model for Custom Flat Windows
    /// </summary>
    class WindowsViewModel
    {
        #region Private Member
        #endregion
        #region Public Properties

        #endregion
        #region Constructor
        // Default Constructor
        public WindowsViewModel(Window window)
        {
            mWindow = window;
            //Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                OnPropertyChanged(nameof(ResizeBorderThickness)); // I got error here
            };
        }
        #endregion
    }
}

WindowsViewModel需要从BaseViewModel继承才能访问其成员

public class WindowsViewModel : BaseViewModel {
    //...
}

相关内容

  • 没有找到相关文章