<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. Perl语言入门--5--散列、hash

    hash 一.关联数组的形式 %h=('a',1,'b',2);         a是key 1是value    b是key  2是value 以%开头,()为空散列 %h=('a'=>1,' ...

  2. MinGW 创建的程序或 DLL 脱离 libgcc-xx-xx.dll 和 libstdc++-x.dll 运行库的方法

    MinGW 沿袭了 Linux 下 gcc/g++ 的习惯,编译出的程序或者动态链接库(共享库)总是默认采用动态链接方式,需要系统中附带运行时库文件 libgcc-xx-xx.dll 和 libstd ...

  3. 重新实践《轻量级DJANGO》这本书

    从手到尾,手写的DJANGO,不借助命令,效果一样的呢. import os import sys import hashlib from django.conf import settings DE ...

  4. 微信小程序之视图容器(swiper)组件创建轮播图

    一.视图容器(Swiper) 1.swiper:滑块视图容器 微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/swi ...

  5. js-classList修改class属性

    classList定义与用法 1)classList属性返回元素的类名,作为DOMTokenList对象 2)该属性用于在元素中添加,移除及切换css类 3)classList属性是只读的,但可以用a ...

  6. Mybatis Generator插件和PageHelper使用

    最近,开始接触web项目开发,项目使用springboot和mybatis,以前一直以为开发过程中实体类,mybatis的xml文件都需要自己手动的去创建. 同事推荐说Mybatis Generato ...

  7. bash帮助文档简单学习;bash手册翻译

    关于bash的四种工作方式的不同,可以参考:http://feihu.me/blog/2014/env-problem-when-ssh-executing-command-on-remote/,但是 ...

  8. JavaScript-4.7-friendly_table---ShinePans

    <html> <head> <meta http-equiv="content-type" content="text/html;chars ...

  9. Android 学习之逐帧动画(Frame)

    帧动画就是将一些列图片.依次播放. 利用肉眼的"视觉暂留"的原理,给用户的感觉是动画的错觉,逐帧动画的原理和早期的电影原理是一样的. a:须要定义逐帧动画,能够通过代码定义.也能够 ...

  10. Android手机需要安装任务管理软件吗?

    使用android手机的用户可能都安装了任务管理的软件,使用android手机真的有必要安装结束任务的软件吗?大家在使用中也都发现了,很多软件在被结束后,马上就会又出现在任务列表里,或是稍等一会自己也 ...