我想要一个按钮来显示应用程序设置窗口,如下所示:
<Window.Resources>
<local:SettingsWindow x:Key="SettingsWnd"/>
</Window.Resources>
<Window.DataContext>
<local:MyViewModel/>
</Window.DataContext>
<Button Command="{Binding ShowSettingsCommand}"
CommandParameter="{DynamicResource SettingsWnd}"/>
ViewModel 有点像:
class MyViewModel : BindableBase
{
public MyViewModel()
{
ShowSettingsCommand = new DelegateCommand<Window>(
w => w.ShowDialog());
}
public ICommand ShowSettingsCommand
{
get;
private set;
}
}
问题是它只能工作一次,因为您无法重新打开以前关闭的窗口。显然,上面的 XAML 不会像那样打开新实例。
有没有办法在CommandParameter
每次调用命令时传递新窗口?