<Window x:Class="WPFPopup.RuntimePopup"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="RuntimePopup" Height="800" Width="800" Loaded="Window_Loaded">
    <StackPanel>
        <Button Height="300">T</Button>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <CheckBox Name="PCheckBox" Width="100" Margin="60,10,0,0"
              Content="Popup Window"/>
            <CheckBox Name="PCheckBox2" Grid.Column="1" Width="100" Margin="0,10,0,0"
              Content="Popup Window"/>
        </Grid>
        
        <Button HorizontalAlignment="Left" Width="169" Margin="10,10,0,0">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                Storyboard.TargetName="theTransform"
                Storyboard.TargetProperty="(RotateTransform.Angle)"
                From="0" To="360" Duration="0:0:5" AutoReverse="True"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
            Start Animation
        </Button>
        <Popup x:Name="popusBottom" IsOpen="{Binding ElementName=PCheckBox,Path=IsChecked}"
           PlacementTarget="{Binding ElementName=PCheckBox}"           
           AllowsTransparency="True"
           PopupAnimation="Fade"
           HorizontalOffset="5"
           VerticalOffset="-120" 
               
           >   
            <Canvas  Margin="150" Background="Green">
                <Canvas.RenderTransform>
                    <RotateTransform x:Name="theTransform" />
                </Canvas.RenderTransform>
                <WrapPanel >
                    <WrapPanel.Background>
                        <ImageBrush ImageSource="BG.png"/>
                    </WrapPanel.Background>
                     <Button Click="Button_Click" Margin="15">Test</Button>
                    <ListBox Height="90" Margin="15">
                        <ListBoxItem>Item1</ListBoxItem>
                        <ListBoxItem>Item2</ListBoxItem>
                        <ListBoxItem>Item3</ListBoxItem>
                        <ListBoxItem>Item1</ListBoxItem>
                        <ListBoxItem>Item2</ListBoxItem>
                        <ListBoxItem>Item3</ListBoxItem>
                        <ListBoxItem>Item1</ListBoxItem>
                        <ListBoxItem>Item2</ListBoxItem>
                        <ListBoxItem>Item3</ListBoxItem>
                    </ListBox>
                </WrapPanel>
                
            </Canvas>
        </Popup>
        <Popup x:Name="popusBottom2" IsOpen="{Binding ElementName=PCheckBox2,Path=IsChecked}"
           PlacementTarget="{Binding ElementName=PCheckBox2}"           
           AllowsTransparency="True"
           PopupAnimation="Fade"
           HorizontalOffset="5"
           VerticalOffset="-120"                  
           >
            <Canvas Margin="150">
                <WrapPanel >
                    <WrapPanel.Background>
                        <ImageBrush   ImageSource="BG.png"/>
                    </WrapPanel.Background>
                    <Button Click="Button_Click" Margin="15">Test</Button>
                    <ListBox Height="90" Margin="15">
                        <ListBoxItem>Item1</ListBoxItem>
                        <ListBoxItem>Item2</ListBoxItem>
                        <ListBoxItem>Item3</ListBoxItem>
                        <ListBoxItem>Item1</ListBoxItem>
                        <ListBoxItem>Item2</ListBoxItem>
                        <ListBoxItem>Item3</ListBoxItem>
                        <ListBoxItem>Item1</ListBoxItem>
                        <ListBoxItem>Item2</ListBoxItem>
                        <ListBoxItem>Item3</ListBoxItem>
                    </ListBox>
                </WrapPanel>
 
            </Canvas>
        </Popup>
    </StackPanel>
 
</Window>

  

C# code

public partial class RuntimePopup : Window
   {
       public RuntimePopup()
       {
           InitializeComponent();
           LocationChanged += new EventHandler(RuntimePopup_LocationChanged);
       }
 
       void RuntimePopup_LocationChanged(object sender, EventArgs e)
       {
           var mi = typeof(Popup).GetMethod("UpdatePosition", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
           mi.Invoke(popusBottom, null);//控制popup随window移动而移动
       }
 
       private void Button_Click(object sender, RoutedEventArgs e)
       {
           MessageBox.Show("Test");
       }
   }

WPF popup控件的使用的更多相关文章

  1. WPF Popup 控件导致被遮挡内容不刷新的原因

    WPF Popup 控件导致被遮挡内容不刷新的原因 周银辉 今天在写一个WPF控件时用到了Popup控件,很郁闷的情况是:当popup关闭时,原来被popup挡住的界面部分不刷新,非要手动刷新一下(比 ...

  2. 自定义WPF Popup控件

    解决问题 1.WPF Popup 不随着 Window 一起移动的问题 2.WPF Popup 总是显示在最前面 引用命名空间 xmlns:ctrl="clr-namespace:Micro ...

  3. 解决wpf popup控件遮挡其他程序的问题

    public class PopupNonTopmost : Popup { public static DependencyProperty TopmostProperty = Window.Top ...

  4. wpf 客户端【JDAgent桌面助手】开发详解(四) popup控件的win8.0的bug

    目录区域: 业余开发的wpf 客户端终于完工了..晒晒截图 wpf 客户端[JDAgent桌面助手]开发详解-开篇 wpf 客户端[JDAgent桌面助手]详解(一)主窗口 圆形菜单... wpf 客 ...

  5. 关于WPF中Popup控件的小记

    在wpf开发中,常需要在鼠标位置处弹出一个“提示框”(在此就以“提示框”代替吧),通过“提示框”进行信息提示或者数据操作,如果仅仅是提示作用,使用ToolTip控件已经足够,但是有些是需要在弹出的框中 ...

  6. WPF中Popup控件在Win7以及Win10等中的对齐点方式不一样的解决方案 - 简书

    原文:WPF中Popup控件在Win7以及Win10等中的对齐点方式不一样的解决方案 - 简书 最近项目中使用弹出控件Popup,发现弹出框的对齐方式在不同的系统中存在不同(Popup在win10上是 ...

  7. 【WPF】使用Popup控件做浮窗/提示框

    需求:当鼠标移入某个区域时,弹出一个浮窗,以便用户进行下一步操作. 效果如下图: 当鼠标移入左上角的[多选显示]框内,出现下面的浮窗(悬浮在原UI之上).当在浮窗外点击鼠标左键时,隐藏该浮窗. 由于该 ...

  8. WPF中Popup控件的使用

    一.Popup控件的主要属性 Popup表示具有内容的弹出窗口,其主要属性为: Child:获取或设置 Popup控件的内容. IsOpen:获取或设置一个值,该值指示Popup 是否可见 Place ...

  9. 迟到的 WPF 学习 —— 控件

    这一章书中内容比较多而杂,但每个对象的内容又相对简短,所以只挑选里边有代表性的内容做记录. 1. Label 控件:一个基础的简单的 ContentControl,Labe 支持快捷键文本的设置,可以 ...

随机推荐

  1. 代码动态改变 NGUI UILabel 的字体

    有一次因为 ttf 分成简体和繁体两个..所以就需要动态改变NGUI 中 UILabel 的字体,但是不知道 UILabel 保存字体的字段是哪个 网上搜到..在这里记录一下 using UnityE ...

  2. Android组件实例化问题

    对于Application. Activity. Notification. BroadCast. Service 这些组件的使用,对象的实例化问题各有不同,如何实例化以及在什么时候实例化也所有不同. ...

  3. [转] iOS应用中通过设置VOIP模式实现休眠状态下socket的长连接

      转自:http://blog.csdn.net/missautumn/article/details/17102067 如果你的应用程序需要在设备休眠的时候还能够收到服务器端发送的消息,那我们就可 ...

  4. Purpose of XMLString::transcode

    原文地址http://stackoverflow.com/questions/9826518/purpose-of-xmlstringtranscode I don't seem to underst ...

  5. AC日记——一元三次方程求解 洛谷 P1024

    题目描述 有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差 ...

  6. 洛谷—— P1873 砍树

    https://www.luogu.org/problemnew/show/P1873 题目描述 伐木工人米尔科需要砍倒M米长的木材.这是一个对米尔科来说很容易的工作,因为他有一个漂亮的新伐木机,可以 ...

  7. FMDB使用的数据库的三种形式

    FMDB使用的数据库的三种形式   FMDB是iOS平台下一款优秀的第三方SQLite数据库框架.它以Objective-C的方式封装了SQLite的C语言API.使用起来,它更加面向对象,避免冗余的 ...

  8. JD静态网页

    1.制作导航栏 ul>li*n>a 2.制作竖线 a.利用border b.利用  | c.利用矩形,宽度设为1,设置背景色,padding = 0 3.制作下三角 (1)◇ (2)两个盒 ...

  9. JDK1.8和Spring 3.2.0 的坑

    上午 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized e ...

  10. Java中没有C#的out关键字,但可以通过数组实现类似的效果

    其实传递的就是数组的指针,里面的每一项的值还是那块内存,所以能直接操作里面的值.如果单纯传指定的值,那么里面操作的就是新的一块内存块. 用数组实现的效果如下: class B{ String cnt= ...