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);//控制popup随window移动而移动
           }
     
           private void Button_Click(object sender, RoutedEventArgs e)
           {
               MessageBox.Show("Test");
           }
       }
  • 相关阅读:
    [Castle]Asp.Net中获取Castle容器中的服务的另一方法
    IBatis.Net如何支持多个数据库
    [Castle]Castle.Model被Castle.Core代替了
    [Castle]Castle也范型
    Since NHibernate 1.2.0, objects are lazy by default
    [django]newforms两种方式示例
    [django]the story about Django and TurboGears
    在docker中运行ElasticSearch时报错:docker: invalid reference format: repository name must be lowercase.
    连接Kibana报错:Kibana server is not ready yet
    Win10系统开启虚拟机屏幕蓝屏自动重启
  • 原文地址:https://www.cnblogs.com/sjqq/p/7806468.html
Copyright © 2011-2022 走看看