내용 보기

작성자

관리자 (IP : 172.17.0.1)

날짜

2020-07-10 01:45

제목

[WPF] 유저컨트롤 Visible될때 에니메이션 효과


아래 유저컨트롤을 Add한후 Visibility="Visible"일 경우 에니메이션 효과가 적용되면서 표시된다.

<UserControl x:Class="WpfApplication5.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Height="324" Width="506" Loaded="UserControl_Loaded">
    <UserControl.Style>
        <Style TargetType="UserControl">
            <Style.Triggers>
                <Trigger Property="Visibility" Value="Visible">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Width" From="0" To="500" Duration="0:0:1" FillBehavior="HoldEnd" AutoReverse="False" />
                                <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="500" Duration="0:0:2" FillBehavior="HoldEnd" AutoReverse="False"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>
    
    <Grid x:Name="grid">
            <TextBox Text="aaaaaaaaaaaaaa" />
    </Grid>
</UserControl>
cs


출처1

출처2