wpf 下不同类型文件使用mvvm模式绑定控件属性方式

1.绑定新建类文件(使用BindableBase方式)

public class   sample:BindableBase
{
        private double blendPreVolume;
        /// <summary>
        /// 混匀前吸体积
        /// </summary>
        public double BlendPreVolume
        {
            get => blendPreVolume;
            set => SetProperty(ref blendPreVolume, value);
        }
}

2.绑定类似于控件类,如usercontrol、window(使用INotifyPropertyChanged方式)

public partial class SampleDataStandardCurveControl : UserControl, INotifyPropertyChanged
{

        

      public event PropertyChangedEventHandler PropertyChanged;

      // 当属性值改变时调用此方法
      protected void OnPropertyChanged(string name)
      {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
      }

     private ObservableCollection<string> internalStandards = new ObservableCollection<string>();

        public ObservableCollection<string> InternalStandards
        {
            get { return internalStandards; }
            set { internalStandards = value; OnPropertyChanged(nameof(InternalStandards)); }
        }
}    

 

posted @ 2025-03-06 09:29  echo-efun  阅读(25)  评论(0)    收藏  举报