You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

1 year ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace MVVMDemo
{
public class MainViewModel : BaseViewModel
{
private string _textContent = "Default Content";
public string TextContent { get => _textContent; set => UpdateProperty(ref _textContent, value); }
public ICommand BtnCmd { get; private set; }
public MainViewModel()
{
BtnCmd = new RelayCommand((_) =>
{
//这个就是控制是否启用的条件
return string.IsNullOrEmpty(TextContent);
}, (o) =>
{
// 获取CommandParameter绑定对象
//var view = o as Window;//因为MainWindow继承自Window所以可以这么写
var view = o as MainWindow;
//举个例子: 点击就最大化窗口
if (view != null)
view.WindowState = WindowState.Maximized;
TextContent = "Default Content";
});
}
}
}