zoukankan      html  css  js  c++  java
  • 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");
            }
        }
    

      

  • 相关阅读:
    494 Target Sum 目标和
    493 Reverse Pairs 翻转对
    492 Construct the Rectangle 构建矩形
    491 Increasing Subsequences 递增子序列
    488 Zuma Game 祖玛游戏
    486 Predict the Winner 预测赢家
    485 Max Consecutive Ones 最大连续1的个数
    483 Smallest Good Base
    Django Form组件
    Django Auth组件
  • 原文地址:https://www.cnblogs.com/linlf03/p/2227674.html
Copyright © 2011-2022 走看看