日期:2014-05-20  浏览次数:21123 次

wpf 连续弹出模态对话框的问题
主窗口弹出模态对话框(a)后,再从子模态对话框(a)弹出模态对话框(b)
用鼠标点击父窗口是正常的,但是从任务栏选中窗口(a),居然可以激活窗口(a)
按下空格键,可以继续从窗口(a)中弹出模态对话框(c)

有什么好的解决方案?

代码如下

xaml
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    
    <Grid>
        
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="141,12,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    </Grid>
</Window>



MainWindow.xaml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender , RoutedEventArgs e)
        {
            Window w = new MainWindow();
            w.Owner = this;
            w.ShowDialog();