如何放置close [x]在WPF弹出 [英] How to place close [x] in WPF popup

查看:109
本文介绍了如何放置close [x]在WPF弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功创建使用C#这段代码的弹出和WPF

 <弹出NAME =myPopupISOPEN = 真> 
<标签名称=myLabelCONTENT =这是一个弹出!背景=艾莉斯蓝前景=蓝/>
< /弹出>



我用下面的代码来隐藏它外面当一个鼠标点击和它的作品的权利。

  myPopup.IsOpen = TRUE; 
myPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;
myPopup.StaysOpen = FALSE;
myPopup.Height = 500;
myPopup.Width = 500;
myPopup.IsOpen = TRUE;



我的问题是,我想补充一个关闭按钮(或类似的东西[X])。这个被点击时,就像在Windows窗体对话框中,它会隐藏。任何想法在此先感谢


解决方案

 <弹出NAME =myPopupISOPEN = 真> 
<&StackPanel的GT;
<标签背景=艾莉斯蓝前景=蓝的Horizo​​ntalAlignment =拉伸Horizo​​ntalContentAlignment =右的MouseDown =mouse_DownHandled>
X
< /标签>
<标签名称=myLabelCONTENT =这是一个弹出!背景=艾莉斯蓝前景=蓝/>
< / StackPanel的>
< /弹出>

在mouse_DownHandled事件处理程序,您可以添加代码以关闭届弹出


I have succeed creating a popup using this code in c# and wpf

<Popup Name="myPopup" IsOpen="True">
<Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
        </Popup> 

I use the code below to hide it when one mouse-click outside it and it works right.

myPopup.IsOpen = true;
myPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;
myPopup.StaysOpen = false;
myPopup.Height = 500;
myPopup.Width = 500;
myPopup.IsOpen = true;

My problem is that I would like to add a close button(or something like [x]). It will hide when this is clicked, just like dialog in windows forms. Any ideas?Thanks in advance

解决方案

<Popup Name="myPopup" IsOpen="True">
    <StackPanel>
        <Label Background="AliceBlue" Foreground="Blue" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" MouseDown="mouse_DownHandled">
        x
        </Label>
        <Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
    </StackPanel>
</Popup>

In the mouse_DownHandled event handler, you can add the code to close th popup

这篇关于如何放置close [x]在WPF弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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