• 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);//控制popup随window移动而移动
           }
     
           private void Button_Click(object sender, RoutedEventArgs e)
           {
               MessageBox.Show("Test");
           }
       }
  • 相关阅读:
    对png空白部分取消button事件教程
    Flash Builder4.6破解方案(绝对有效)
    网页程序Flex动态嵌入字体
    老虎机等转动图片思路
    我认为最佳的新手引导制作办法
    26
    sql server 2005建立数据库,表,约束,账户密码,权限,基本查询删除语句
    ASP.NET入门教程:ASP.NET和ASP区别
    .net面试题及答案(一)(转)
    ASP.NET入门教程:认识ASP.NET
  • 原文地址:https://www.cnblogs.com/sjqq/p/7806468.html
Copyright © 2020-2023  润新知