Question

I have a user control that I'd like to show when the user clicks a button. That's not a problem, using af Popup control.

However, I'd like to have the user control fade-in and scale from 0.5 to 1.2 and back to 1.0 (both X and Y) at the same time.

How do I do that?

Was it helpful?

Solution

WPF Popups are not transparent, so fade in and fade out won't really work. You can set Opacity all you want, but that won't change a thing. However, you could play with the Tooltip. It's pretty close to a popup. Anyway, here's something to get you started:

<UserControl x:Class="WpfApplication1.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Style>
    <Style>
        <Style.Triggers>
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:02" From="0" To="1" />
                    </Storyboard>
                </BeginStoryboard>                  
            </EventTrigger>
            <Trigger Property="FrameworkElement.Visibility" Value="Collapsed">
                <Setter Property="FrameworkElement.Opacity" Value="0"/>             
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Style>
<Border x:Name="border" BorderBrush="Blue" BorderThickness="3" CornerRadius="3" Padding="3" Background="Orange"
    Width="175" Height="175">
    <TextBlock Text="Sample" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>

plop it somewhere, I am using a tooltip on the same button, just for demonstration purpose:

<Button Click="OnButtonClick" Content="click to see popup">
        <Button.ToolTip>
            <ToolTip x:Name="popup" IsOpen="False" Background="Transparent" BorderBrush="Transparent" 
                     Placement="Bottom">
                <WpfApplication1:UserControl1/>
            </ToolTip>
        </Button.ToolTip>
    </Button>

for OnButtonClick code behind, I just toggleed the popup so I can click it more than once:

private void OnButtonClick(object sender, RoutedEventArgs e)
{
    popup.IsOpen = !popup.IsOpen;
}

OTHER TIPS

WPF popups can handle transparency, just set the following

<Popup AllowsTransparency="True" PopupAnimation="Fade">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top