WPF-工作区切换-工作区缩略图

来源:转载

 

如图上的效果,中间是工作区,点击按钮可以增加新的工作区,并且在左边的快捷区域中增加新工作区的缩略图,点击左边的工作区缩略图可以切换回去。

前台代码:

<Window x:Class="Easting.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="478" Width="825" Loaded="Window_Loaded"> <Grid> <Border Panel.ZIndex="1" CornerRadius="3" BorderBrush="Black" Background="Black" BorderThickness="1" Opacity="0.5" HorizontalAlignment="Left" VerticalAlignment="Center"> <StackPanel x:Name="WorkLocation"/> </Border> <StackPanel Name="WorkPanel"> <ToolBar> <Button x:Name="AddWork" Content="AddWork" Click="AddWork_Click" /> </ToolBar> <Grid x:Name="WorkLocationPanel"> <DockPanel x:Name="defaultLocation" LastChildFill="True"> <TextBlock Background="Yellow" Width="500" Height="500" Text="默认工作区" FontSize="50"/> </DockPanel> </Grid> </StackPanel> </Grid></Window>

后台代码:

namespace Easting{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }  public void AddWorkLocation(FrameworkElement element) { ScaleTransform scale = new ScaleTransform(); Rectangle item = new Rectangle() { Width = 50, Height = 50, Fill = new VisualBrush() { Visual = element }, Margin = new Thickness(3), RenderTransformOrigin = new Point(0.5, 0.5), RenderTransform = scale }; item.MouseLeftButtonDown += new MouseButtonEventHandler(delegate { WorkLocationPanel.Children.Clear(); WorkLocationPanel.Children.Add(element); }); #region 鼠标进入区域放大 item.MouseEnter += new MouseEventHandler(delegate { EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseOut, //公式 Oscillations = 5, //滑过动画目标的次数 Springiness = 10 //弹簧刚度 }; DoubleAnimation inAnimation = new DoubleAnimation() { From = 1, //起始值 To = 1.2, //结束值 EasingFunction = easing, //缓动函数 Duration = new TimeSpan(0, 0, 0, 1, 200) //动画播放时间 }; AnimationClock clock = inAnimation.CreateClock(); scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock); scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock); }); #endregion #region 鼠标离开区域缩小 item.MouseLeave += new MouseEventHandler(delegate { EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseOut, //公式 Oscillations = 5, //滑过动画目标的次数 Springiness = 10 //弹簧刚度 }; DoubleAnimation outAnimation = new DoubleAnimation() { From = 1.2, //起始值 To = 1, //结束值 EasingFunction = easing, //缓动函数 Duration = new TimeSpan(0, 0, 0, 1, 200) //动画播放时间 }; AnimationClock clock = outAnimation.CreateClock(); scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock); scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock); }); #endregion WorkLocation.Children.Add(item); } private void Window_Loaded(object sender, RoutedEventArgs e) { AddWorkLocation(defaultLocation); } int index = 0; private void AddWork_Click(object sender, RoutedEventArgs e) { DockPanel newWork = new DockPanel(); TextBlock item = new TextBlock() { Background = Brushes.Gray, Text = "工作区" + (index++).ToString(), FontSize = 100, Width = 500, Height = 500  }; newWork.Children.Add(item); AddWorkLocation(newWork); WorkLocationPanel.Children.Clear(); WorkLocationPanel.Children.Add(newWork); } }}

原文地址:http://www.luacloud.com/2011/06/10/wpf-%e5%b7%a5%e4%bd%9c%e5%8c%ba%e5%88%87%e6%8d%a2-%e5%b7%a5%e4%bd%9c%e5%8c%ba%e7%bc%a9%e7%95%a5%e5%9b%be/

分享给朋友:
您可能感兴趣的文章:
随机阅读: