• WPF popup控件的使用


    <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);
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                MessageBox.Show("Test");
            }
        }
    

      

  • 相关阅读:
    【Java 学习笔记】 问题列表
    【Weka】Weka聚类
    【MFC 学习笔记】MFC BUG
    【Java 学习笔记】 变量转换
    【MFC 学习笔记】CheckListBox
    Http Handler 介绍
    C# HttpWebRequest可断点上传,下载文件;SOCKET多线程多管道可断点传送大文件
    SQL Server 2005 常用数据类型详解
    浅谈OCR之Tesseract
    [理财产品] 招行新的日日金8158
  • 原文地址:https://www.cnblogs.com/linlf03/p/2227674.html
Copyright © 2020-2023  润新知