思路:在主窗体出来之前,弹出登录框,如果验证成功关掉登录框。
LoginView 样式
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="Width" Value="1024" />
<Setter Property="Height" Value="512" />
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
</Style>
</prism:Dialog.WindowStyle>
LoginViewModel代码
继承IDialogAware
登录成功使用
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
在APP代码中添加
在主窗渲染之前弹框
protected override void OnInitialized()
{
var dialog = Container.Resolve<IDialogService>();
dialog.ShowDialog("LoginView", callback =>
{
if (callback.Result != ButtonResult.OK)
{
Environment.Exit(0);
return;
}
//给主窗体传值
base.OnInitialized();
});
}
2.切换用户
public static void LoginOut(IContainerProvider containerProvider)
{
Current.MainWindow.Hide();
var dialog = containerProvider.Resolve<IDialogService>();
dialog.ShowDialog("LoginView", callback =>
{
if (callback.Result != ButtonResult.OK)
{
Environment.Exit(0);
return;
}
//给主窗体传值
Current.MainWindow.Show();
});
}