我是Prism Framework的WPF开发的新手。我观看了Brian的一些视频,以了解这两个论点。现在,我正在开发一个应用程序,但是尝试在主窗口之前打开自定义窗口对话框时遇到了问题。这是我打开的简单窗口:
<Window x:Class="Dinamo.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Dinamo"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Grid>
<TextBox>WINDOW</TextBox>
</Grid>
</Window>
和分类为xaml.cs
public partial class Window1 : Window, IDialogWindow
{
public Window1()
{
InitializeComponent();
}
public IDialogResult Result { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
这是我的shell类:
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialogWindow<Window1>();
}
}
和MainWindowViewModel
public MainWindowViewModel(IDialogService dialogService)
{
dialogService.ShowDialog("Window1", null, null);
}
但是当我尝试此代码时,我收到错误:'A dialog's content must be a FrameworkElement'
我做错了什么?
提前感谢。
窗口名称是第四个参数。第一个应该是UserControl
,它定义对话框窗口的内容:
dialogService.ShowDialog("UserControl1", null, null, "Window1");
您会找到一个示例here。