嗨,我想在单击按钮时显示确认窗口。我正在尝试使用 MVVM 设计模式进行开发,我已经实现了,但我不认为在 viewModel 中调用视图
是正确的方法。我已经附上了代码,请检查它是否正确
<Window x:Class="MessegeBox_Demo_2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Ckick ME" HorizontalAlignment="Left"
Command="{Binding GetMessegeboxCommand}"
Margin="200,131,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
public class MainWindowViewModel : ViewModelBaseClass
{
private ICommand _getMessegeboxCommand;
public ICommand GetMessegeboxCommand
{
get
{
return _getMessegeboxCommand ?? (_getMessegeboxCommand = new MessegeBox_Demo_2.Command.realyCommand(() => ShowUsercontrol(), true));
}
}
private void ShowUsercontrol()
{
MessegeBox_Demo_2.View.Window1 mbox = new View.Window1();
mbox.ShowDialog();
}
}
Run Code Online (Sandbox Code Playgroud)