ShowDialog
方法在关闭设置对话框之前不会返回。
OnStartup
方法:
protected override void OnStartup(object sender, StartupEventArgs e)
{
base.OnStartup(sender, e);
DisplayRootViewFor<MainViewModel>();
dynamic settings = new ExpandoObject();
settings.WindowStartupLocation = WindowStartupLocation.CenterOwner;
settings.ResizeMode = ResizeMode.NoResize;
var settingsVm = new SettingsViewModel(_container.GetInstance<IEventAggregator>());
var result = _container.GetInstance<IWindowManager>()
.ShowDialog(settingsVm, null, settings);
settingsVm.Start();
}
主视图模型:
class MainViewModel : PropertyChangedBase, IHandle<Settings>
{
private Settings _settings;
private readonly IEventAggregator _eventAggregator;
private readonly IWindowManager _windowManager;
public MainViewModel(IEventAggregator eventAggregator, IWindowManager windowManager)
{
_eventAggregator = eventAggregator;
_eventAggregator.Subscribe(this);
_windowManager = windowManager;
}
public void Handle(Settings message)
{
_settings = message;
// Continue here ...
}
}