我有简单的WPF应用程序,主窗口和按钮,点击后会创建一个新的模态子项 通过我的窗口管理器窗口:
class WindowManager : IWindowManager
{
public void AddNewViewWindow()
{
var someWindow = new AddNewView();
someWindow.ShowInTaskbar = false;
someWindow.Owner = Application.Current.MainWindow;
someWindow.ShowDialog();
}
}
主窗口:
<Window x:Class="LogView.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525">
<StackPanel>
<StackPanel Orientation="Horizontal">
<ContentControl prism:RegionManager.RegionName="ContentRegion" />
<Button Name="AddNewControl" Content="Add New Control" Command="{Binding AddNewViewCommand}" Margin="10">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<CheckBox Name="EditMode" Content="Edit mode" IsChecked="{Binding EditModeEnabled}" Margin="10"/>
</StackPanel>
</StackPanel>
</Window>
ModalChildWindow:
<Window x:Class="LogView.Views.AddNewView"
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:LogView.Views"
xmlns:prism ="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Title="AddNewView" Height="450" Width="800">
<StackPanel>
<TreeView ItemsSource="{Binding DeviceSets}" >
<TreeView.ItemTemplate>
<DataTemplate>
<TreeViewItem Header="{Binding Name}" ItemsSource="{Binding Registers}">
<TreeViewItem.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Name}">
</TextBox>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</StackPanel>
</Window>
我也在使用Prism,我的引导程序:
class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
RegisterTypeIfMissing(typeof(IWindowManager), typeof(WindowManager), true);
}
protected override void ConfigureModuleCatalog()
{
var moduleCatalog = (ModuleCatalog)ModuleCatalog;
moduleCatalog.AddModule(typeof(WebSocketClientModule));
}
}
现在,我遇到了这种奇怪的行为:
单击按钮时,会显示模态子窗口。一切都很好,我无法点击父(MainWindow)窗口。然后,如果我最小化这个子模态窗口,然后重新打开它,子窗口将停止模态。我可以单击MainWindow并创建第二个模态窗口(第一个仍然可见)。甚至奇怪,第二个模态窗口是真正的模态,当我最小化它,把它带上我不能点击父窗口。如果我关闭第二个模态窗口,我可以再次创建它。 问候