当我在打开dialoghost的过程中打开新的用户控件到dialoghost时发生此错误:
当我按提交按钮这是我的代码xaml:
主窗口:
<Grid>
<Button Content="Show"
Command="{Binding OpenRegisCommand}"
VerticalAlignment="Bottom"
Margin="0 0 0 40"
Foreground="White"
Width="100"
Background="#23A9F2">
</Button>
<md:DialogHost Identifier="RootDialogHostId">
</md:DialogHost>
</Grid>
我的用户控件和主窗口使用1个视图模型:
public MainViewModel()
{
OpenRegisCommand = new DelegateCommand(OpenFormRegis);
Submit = new DelegateCommand(Check);
}
private async void Check()
{
if(Name.Equals("admin")&&Pass.Equals("123456"))
{
var view = new DialogOk();
await DialogHost.Show(view, DialogHostId);
}
else
{
var view = new DialogNo();
await DialogHost.Show(view, DialogHostId);
}
}
private async void OpenFormRegis()
{
var view = new FormRegis();
await DialogHost.Show(view, DialogHostId);
}
按钮提交在我的用户控件中绑定到DelegateCommand提交在我的视图模型中
2条答案
按热度按时间k5hmc34c1#
每个对话框主机可用于一次显示一个视图。
如果要同时拍摄两个视图(不太可能),则需要两个对话框主体。
在您的情况下,如果您试图在对话框宿主中打开“OpenFormRegis”窗口,我建议您使用Windows。
huus2vyu2#
在我的案例中,我做了以下操作:
1-使用DialogHost.GetDialogSession(“RootDialog”)获取活动的对话框。
2-如果它不是null,则使用UpdateContent(alertBox)方法设置内容,该方法更新对话框的内容。
3-如果为空,则建立常规流以显示对话框的内容。