글
<Grid>
<Button FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button.Content>Expanding Button</Button.Content>
<Button.Triggers>
<!--EventTrigger : C#의 이벤트와 가장 비슷한 개념-->
<!--RoutedEvent : 이벤트 종류 설정-->
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard><!--애니메이션 사용-->
<Storyboard>
<DoubleAnimation
From="12"
To="72"
Duration="0:0:.5"
Storyboard.TargetProperty="FontSize"/>
<!--수치값변화-->
<!-- 12부터 72까지 0시간0분0.5초동안 FontSize변화-->
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
c#구현
private double init = 12; //멤버변수
private double max = 72;
private Button btn;
public Trigger()
{
InitializeComponent();
btn = new Button();
btn.Content = "Expanding Button";
btn.FontSize = init;
btn.HorizontalAlignment = HorizontalAlignment.Center; //정렬위치
btn.VerticalAlignment = VerticalAlignment.Center;
btn.Click += new RoutedEventHandler(btn_Click);//Click Event
this.Content = btn;//버튼추가
}
void btn_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation da = new DoubleAnimation(); //DoubleAnimation
da.From = init; //시작값
da.To = max; //끝값
da.Duration = new Duration(TimeSpan.FromSeconds(2));//
btn.BeginAnimation(Button.FontSizeProperty, da);//실행
}
RECENT COMMENT