单击时需要激活两个弹出控件 [英] Two Popup Controls need to be activated when clicked

查看:56
本文介绍了单击时需要激活两个弹出控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主窗口,在点击text1,text2 - >时提供了两个标签(Text1,Text2)。打开了两个弹出窗口控件,但是当一个弹出窗口(第一个或第二个)是预先安装而另一个弹出窗口是单击向下时,它没有预先显示而是显示在其他弹出窗口(第一个或第二个)之后....对于我的WPF应用程序

我在网上搜索并获得了BringtoFrontBehavior的行为,该行为专门用于面板而不是用于控件而且我不知道如何在我的行为中添加此行为现有项目...请帮助

 

解决方案

这里的部分问题是弹出窗口是排序在他们自己的可视树中,他们没有包含面板,您可以在其中轻松设置z顺序。最好的选择可能是关闭/重新打开弹出窗口,这将把它放在最顶层。

 

这是一个简单的例子:

<网格x:名称=" LayoutRoot"> 
< Label Horizo​​ntalAlignment =" Left"余量= QUOT; 24,26,0,0" VerticalAlignment = QUOT;陀螺" Content =" Label 1"宽度= QUOT; 60.75"的MouseLeftButtonUp = QUOT; Label1Click" />
< Label Horizo​​ntalAlignment =" Left"余量= QUOT; 24,55.96,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 60.75" Content =" Label 2"的MouseLeftButtonUp = QUOT; Label2Click" />
< Popup x:Name =" Popup1"余量= QUOT; 0"放置= QUOT;小鼠">
<网格宽度=" 100"高度= QUOT; 100"背景= QUOT;红色" />
< / Popup>
< Popup x:Name =" Popup2"余量= QUOT; 2,2,-2,-2 QUOT;放置= QUOT;小鼠">
<网格宽度=" 100"高度= QUOT; 100"背景= QUOT;#FF57FF2A" />
< / Popup>
< / Grid>

 private void Label1Click(object sender,System.Windows.Input.MouseButtonEventArgs e)
{
this.Popup1.IsOpen = false;
this.Popup1.IsOpen = true;
}

private void Label2Click(object sender,System.Windows.Input.MouseButtonEventArgs e)
{
this.Popup2.IsOpen = false;
this.Popup2.IsOpen = true;
}

此外,您尝试使用的行为适用于Silverlight,因此您无法将其添加到WPF项目中。


I have one main window, in which two labels are provided (Text1, Text2) on clicking of the text1, text2 -> two popup controls are opened, but when one popup (either first or second) is upfront and the other one is down when clicking on the down one it is not showing upfront rather it is behind the other popup (first or second)....for my WPF applications

I have searched in the net and got the behavior as BringtoFrontBehavior which is exclusively for panels and not for the controls and I dont' know how to add this behavior in my existing project... please help

 

解决方案

Part of the problem here is that popups are sort of in a visual tree of their own, they don't have a containing panel in which you can easily set the z-order. The best option is probably to close/re-open the popup, which will place it on top.

 

Here is a simple example:

<Grid x:Name="LayoutRoot">
		<Label HorizontalAlignment="Left" Margin="24,26,0,0" VerticalAlignment="Top" Content="Label 1" Width="60.75" MouseLeftButtonUp="Label1Click"/>
		<Label HorizontalAlignment="Left" Margin="24,55.96,0,0" VerticalAlignment="Top" Width="60.75" Content="Label 2" MouseLeftButtonUp="Label2Click"/>
		<Popup x:Name="Popup1" Margin="0" Placement="Mouse">
			<Grid Width="100" Height="100" Background="Red"/>
		</Popup>
		<Popup x:Name="Popup2" Margin="2,2,-2,-2" Placement="Mouse">
			<Grid Width="100" Height="100" Background="#FF57FF2A"/>
		</Popup>
	</Grid>

private void Label1Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			this.Popup1.IsOpen = false;
			this.Popup1.IsOpen = true;
		}

		private void Label2Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			this.Popup2.IsOpen = false;
			this.Popup2.IsOpen = true;
		}

Also, that behavior you were trying to use is for Silverlight, so you won't be able to add it to your WPF project.


这篇关于单击时需要激活两个弹出控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆