728x90
반응형
WPF & C# - Scrolling StackPanle ( 스택패널 스크롤링 / FluidMoveBehavior / Cnavas / 캔버스 ) |
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 | <Canvas x:Name="canvas"> <StackPanel x:Name="stp" Orientation="Horizontal"> <i:Interaction.Behaviors> <ei:FluidMoveBehavior> <ei:FluidMoveBehavior.EaseY> <CircleEase EasingMode="EaseOut"/> </ei:FluidMoveBehavior.EaseY> <ei:FluidMoveBehavior.EaseX> <CircleEase EasingMode="EaseOut"/> </ei:FluidMoveBehavior.EaseX> </ei:FluidMoveBehavior> </i:Interaction.Behaviors> <StackPanel x:Name="stp1" Grid.Column="1" Margin="10" Background="#FF9CC7F1" Width="100"> <Button Height="100" Content="1" Click="btn1_Click" Background="#FFF3F3BE"/> <Button Height="100" Content="2" Click="btn2_Click" Background="#FFF3F3BE"/> <Button Height="100" Content="3" Click="btn3_Click" Background="#FFF3F3BE"/> </StackPanel> <StackPanel x:Name="stp2" Grid.Column="1" Margin="10" Background="#FF9CC7F1" Width="100"> <Button Height="100" Content="1" Click="btn1_Click" Background="#FF8ADAF1"/> <Button Height="100" Content="2" Click="btn2_Click" Background="#FF8ADAF1"/> <Button Height="100" Content="3" Click="btn3_Click" Background="#FF8ADAF1"/> </StackPanel> <StackPanel x:Name="stp3" Grid.Column="1" Margin="10" Background="#FF9CC7F1" Width="100"> <Button Height="100" Content="1" Click="btn1_Click" Background="#FFF7B09C"/> <Button Height="100" Content="2" Click="btn2_Click" Background="#FFF7B09C"/> <Button Height="100" Content="3" Click="btn3_Click" Background="#FFF7B09C"/> </StackPanel> </StackPanel> </Canvas> | cs |
MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | private void btn1_Click(object sender, RoutedEventArgs e) { Point ptStart = stp.TranslatePoint(new Point(0, 0), canvas); Point ptTarget = stp1.TranslatePoint(new Point(0, 0), canvas); Canvas.SetLeft(stp, ptStart.X - ptTarget.X + 10); } private void btn2_Click(object sender, RoutedEventArgs e) { Point ptStart = stp.TranslatePoint(new Point(0, 0), canvas); Point ptTarget = stp2.TranslatePoint(new Point(0, 0), canvas); Canvas.SetLeft(stp, ptStart.X - ptTarget.X + 10); } private void btn3_Click(object sender, RoutedEventArgs e) { Point ptStart = stp.TranslatePoint(new Point(0, 0), canvas); Point ptTarget = stp3.TranslatePoint(new Point(0, 0), canvas); Canvas.SetLeft(stp, ptStart.X - ptTarget.X + 10); } | cs |
728x90
반응형