WPF MVVM 如何在 ViewModel 中关闭界面窗口
程序员文章站
2022-07-13 22:37:33
...
01 xaml
<Button Width="80"
Command="{Binding CancelCmd}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
</Button>
02 后台cs
private CommandBase cancelCmd;
public CommandBase CancelCmd
{
get
{
if (cancelCmd == null)
{
cancelCmd = new CommandBase(CloseApp, CancelCanExcute);
}
return cancelCmd;
}
}
void CloseApp(object o)
{
var win = o as System.Windows.Window;
win.Close();
}
bool CancelCanExcute(object o) { return true; }
上一篇: etcd 备份与恢复
下一篇: etcd 备份与恢复