■ EventTrigger 엘리먼트에서 CallMethodAction 객체를 사용해 객체 메소드 실행하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" Width="800" Height="600" Title="EventTrigger 엘리먼트 : CallMethodAction 객체를 사용해 객체 메소드 실행하기" FontFamily="나눔고딕코딩" FontSize="16"> <Grid Margin="10"> <Border HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1"> <ScrollViewer Name="scrollViewer" Width="200" Height="200"> <StackPanel> <StackPanel.Resources> <Style TargetType="TextBlock"> <Setter Property="Padding" Value="5" /> </Style> </StackPanel.Resources> <TextBlock Text="A" /> <TextBlock Text="B" /> <TextBlock Text="C" /> <TextBlock Text="D" /> <TextBlock Text="E" /> <TextBlock Text="F" /> <TextBlock Text="G" /> <TextBlock Text="H" /> <TextBlock Text="I" /> <TextBlock Text="J" /> <TextBlock Text="K" /> <TextBlock Text="L" /> <TextBlock Text="M" /> <TextBlock Text="N" /> <TextBlock Text="O" /> <TextBlock Text="P" /> <TextBlock Text="Q" /> <TextBlock Text="R" /> <TextBlock Text="S" /> <TextBlock Text="T" /> <TextBlock Text="U" /> <TextBlock Text="V" /> <TextBlock Text="W" /> <TextBlock Text="X" /> <TextBlock Text="Y" /> <TextBlock Text="Z" /> </StackPanel> </ScrollViewer> </Border> <Button Content="↑" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="20"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <ei:CallMethodAction TargetObject="{Binding ElementName=scrollViewer}" MethodName="ScrollToHome" /> </i:EventTrigger> </i:Interaction.Triggers> </Button> </Grid> </Window> |