<Window x:Class="SDKSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="AnimatedPopup"> <StackPanel> <CheckBox Name="myCheckBox" Margin="20,20,0,0" Content="Select CheckBox to see Popup"/> <Button HorizontalAlignment="Left" Width="200" Margin="20,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> Click to see the Popup animate </Button> </StackPanel> </Window>
Month: February 2011
Rotating Popup
<Window x:Class="SDKSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="AnimatedPopup"> <StackPanel> <Popup IsOpen="{Binding ElementName=myCheckBox,Path=IsChecked}" PlacementTarget="{Binding ElementName=myCheckBox}" AllowsTransparency="True" PopupAnimation="Slide" HorizontalOffset="50" VerticalOffset="50" > <Canvas Width="100" Height="100" Background="DarkBlue" Margin="150"> <Canvas.RenderTransform> <RotateTransform x:Name="theTransform" /> </Canvas.RenderTransform> <TextBlock TextWrapping="Wrap" Foreground="White"> Rotating Popup </TextBlock> </Canvas> </Popup> </StackPanel> </Window>
Create Popup mock in Xaml
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF" Height="150" Width="250"> <StackPanel> <Popup AllowsTransparency="True" Height="100" HorizontalOffset="1cm" Name="myPopup" Placement="Right" StaysOpen="True" Width="200" > <Border BorderBrush="Black" BorderThickness="2"> <DockPanel Background="White" LastChildFill="True"> <TextBlock Background="AliceBlue" DockPanel.Dock="Top" FontSize="16" HorizontalAlignment="Stretch" Margin="5" Text="A WPF Popup" /> <Button Click="btnClosePopup_Click" Content="Close" DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Right" MaxHeight="23"/> <Image DockPanel.Dock="Top" Margin="5" Source="c:image.gif" /> </DockPanel> </Border> </Popup> <StackPanel> <StackPanel.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Margin" Value="2" /> <EventSetter Event="Click" Handler="btnShowPopup_Click" /> </Style> </StackPanel.Resources> <Button Content="Show Popup" Name="btnShowPopup" /> </StackPanel> </StackPanel> </Window> //File:Window.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Controls.Primitives; namespace WpfApplication1 { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void btnClosePopup_Click(object sender, RoutedEventArgs e) { myPopup.IsOpen = false; } private void btnShowPopup_Click(object sender, RoutedEventArgs e) { myPopup.IsOpen = true; } } }
Close a Popup with Button click
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF" Height="150" Width="250"> <StackPanel> <Popup AllowsTransparency="True" Height="100" HorizontalOffset="1cm" Name="myPopup" Placement="Right" StaysOpen="True" Width="200" > <Border BorderBrush="Black" BorderThickness="2"> <DockPanel Background="White" LastChildFill="True"> <TextBlock Background="AliceBlue" DockPanel.Dock="Top" FontSize="16" HorizontalAlignment="Stretch" Margin="5" Text="A WPF Popup" /> <Button Click="btnClosePopup_Click" Content="Close" DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Right" MaxHeight="23"/> <Image DockPanel.Dock="Top" Margin="5" Source="c:image.gif" /> </DockPanel> </Border> </Popup> <StackPanel> <StackPanel.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Margin" Value="2" /> <EventSetter Event="Click" Handler="btnShowPopup_Click" /> </Style> </StackPanel.Resources> <Button Content="Show Popup" Name="btnShowPopup" /> </StackPanel> </StackPanel> </Window> //File:Window.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Controls.Primitives; namespace WpfApplication1 { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void btnClosePopup_Click(object sender, RoutedEventArgs e) { myPopup.IsOpen = false; } private void btnShowPopup_Click(object sender, RoutedEventArgs e) { if (sender == btnShowPopup){ myPopup.IsOpen = true; } } } }
Use Popup to display a hyperlink
<Window x:Class="ClassicControls.PopupTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="PopupTest" Height="300" Width="300"> <Grid Margin="10"> <TextBlock TextWrapping="Wrap">text <Run TextDecorations="Underline" MouseEnter="run_MouseEnter">link</Run> </TextBlock> <Popup Name="popLink" StaysOpen="False" Placement="Mouse" MaxWidth="200" PopupAnimation="Slide" AllowsTransparency = "True"> <Border BorderBrush="Beige" BorderThickness="2" Background="White"> <TextBlock Margin="10" TextWrapping="Wrap" > check out <Hyperlink NavigateUri="http://kutayzorlu.com/java2s/com" Click="lnk_Click">kutayzorlu.com/java2s/com</Hyperlink> </TextBlock> </Border> </Popup> </Grid> </Window> //File:Window.xaml.cs using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Diagnostics; namespace ClassicControls { public partial class PopupTest : System.Windows.Window { public PopupTest() { InitializeComponent(); } private void run_MouseEnter(object sender, MouseEventArgs e) { popLink.IsOpen = true; } private void lnk_Click(object sender, RoutedEventArgs e) { Process.Start(((Hyperlink)sender).NavigateUri.ToString()); } } }
PopupAnimation = PopupAnimation.Fade
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF" Height="150" Width="250"> <StackPanel> <Popup AllowsTransparency="True" Height="100" HorizontalOffset="1cm" Name="myPopup" Placement="Right" StaysOpen="True" Width="200" > <Border BorderBrush="Black" BorderThickness="2"> <DockPanel Background="White" LastChildFill="True"> <TextBlock Background="AliceBlue" DockPanel.Dock="Top" FontSize="16" HorizontalAlignment="Stretch" Margin="5" Text="A WPF Popup" /> <Button Click="btnClosePopup_Click" Content="Close" DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Right" MaxHeight="23"/> <Image DockPanel.Dock="Top" Margin="5" Source="c:image.gif" /> </DockPanel> </Border> </Popup> <StackPanel> <StackPanel.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Margin" Value="2" /> <EventSetter Event="Click" Handler="btnShowPopup_Click" /> </Style> </StackPanel.Resources> <Button Content="Show Popup" Name="btnShowPopup" /> </StackPanel> </StackPanel> </Window> //File:Window.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Controls.Primitives; namespace WpfApplication1 { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void btnClosePopup_Click(object sender, RoutedEventArgs e) { myPopup.IsOpen = false; } private void btnShowPopup_Click(object sender, RoutedEventArgs e) { myPopup.PopupAnimation = PopupAnimation.Fade; myPopup.IsOpen = true; } } }
PopupAnimation = PopupAnimation.Scroll;
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF" Height="150" Width="250"> <StackPanel> <Popup AllowsTransparency="True" Height="100" HorizontalOffset="1cm" Name="myPopup" Placement="Right" StaysOpen="True" Width="200" > <Border BorderBrush="Black" BorderThickness="2"> <DockPanel Background="White" LastChildFill="True"> <TextBlock Background="AliceBlue" DockPanel.Dock="Top" FontSize="16" HorizontalAlignment="Stretch" Margin="5" Text="A WPF Popup" /> <Button Click="btnClosePopup_Click" Content="Close" DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Right" MaxHeight="23"/> <Image DockPanel.Dock="Top" Margin="5" Source="c:image.gif" /> </DockPanel> </Border> </Popup> <StackPanel> <StackPanel.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Margin" Value="2" /> <EventSetter Event="Click" Handler="btnShowPopup_Click" /> </Style> </StackPanel.Resources> <Button Content="Show Popup" Name="btnShowPopup" /> </StackPanel> </StackPanel> </Window> //File:Window.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Controls.Primitives; namespace WpfApplication1 { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void btnClosePopup_Click(object sender, RoutedEventArgs e) { myPopup.IsOpen = false; } private void btnShowPopup_Click(object sender, RoutedEventArgs e) { myPopup.PopupAnimation = PopupAnimation.Scroll; myPopup.IsOpen = true; } } }