关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

WPF:文本模板的应用

发布时间:2020-03-14 00:00:00

项目使用MVVM,创建了一个基类VMBase

using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace YKCore.ViewModels
{
    public class VMBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void RaisePropertyChanged([CallerMemberName]  string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

然后创建继承类的时候,要写一个属性,比较麻烦

        private Visibility _BtnOKV;
        public Visibility BtnOKV
        {
            get=>_BtnOKV;
            set
            {
                _BtnOKV=value;
                RaisePropertyChanged();
            }
        }

折腾了一会文本模板发现不错,比如下面的代码,就能自动生成一个类,效率还是蛮高的!

using System;
using System.Windows;
using System.Windows.Media;

namespace YKCore.ViewModels
{
    public class VMMessageBox : VMBase
    {
public VMCommand Commands{get;set;}
    }
}

/template/Home/Zkeys/PC/Static