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 @   echo-efun  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
历史上的今天:
2024-03-06 视觉专业英语(二)
2024-03-06 基本操作之——tuple增删查改操作
2024-03-06 基本操作之——tuple值分布范围获取
2024-03-06 基本操作之——tuple类型
2024-03-06 基础设置之——条件判断(二)
2024-03-06 基本操作之——字典
点击右上角即可分享
微信分享提示