我写了一段代码来描述我的问题:当点击主窗口上的一个控件时,MouseLeftButtonDown命令显示一个子窗口作为模态。当在子窗口中双击时,将触发主窗口中的MouseLeftButtonUp。如何避免这种情况没有一个标志?
主
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MouseLeftButtonDownCommand(object sender, MouseButtonEventArgs e)
{
ChildWindow childWindow = new ChildWindow();
childWindow.Owner = this;
childWindow.ShowDialog();
}
private void MouseLeftButtonUpCommand(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Event Propagated to main window");
}
}
主XAML
<Grid>
<Canvas Background="Transparent" MouseLeftButtonDown="MouseLeftButtonDownCommand" MouseLeftButtonUp="MouseLeftButtonUpCommand">
</Canvas>
</Grid>
酒店MODAL WINDOWS
public partial class ChildWindow : Window
{
public ChildWindow()
{
InitializeComponent();
}
private void LeftDoubleClickCommand(object sender, MouseButtonEventArgs e)
{
this.Close();
}
}
MODAL WINDOWS XAML
<Grid>
<ListView Margin="10" MouseDoubleClick="LeftDoubleClickCommand">
<ListViewItem Content="Coffie"></ListViewItem>
<ListViewItem Content="Tea"></ListViewItem>
<ListViewItem Content="Orange Juice"></ListViewItem>
<ListViewItem Content="Milk"></ListViewItem>
<ListViewItem Content="Iced Tea"></ListViewItem>
<ListViewItem Content="Mango Shake"></ListViewItem>
</ListView>
</Grid>
1条答案
按热度按时间c3frrgcw1#
在消息循环为空之前,不要关闭对话框窗口:
或将事件标记为已处理: