0

伙计们。我正在实现一个 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));
        }
    }
}

没问题,但是当我在WindowViewModel上调用它时,我收到一个错误,即OnPropertyChanged Not Defined here is my WindowViewModel

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
    }
}
4

1 回答 1

3

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

public class WindowsViewModel : BaseViewModel {
    //...
}
于 2017-06-11T13:50:19.283 回答