原文:Prism for WPF 搭建一个简单的模块化开发框架(六)隐藏菜单、导航

这个实际上是在聊天之前做的,一起写了,也不分先后了

看一下效果图,上面是模块主导航,左侧是模块内菜单,现在加一下隐藏菜单,让中间部分更大

 

直接上代码吧,上下代码基本上一样就只贴左侧的代码了

既然做这个,少不了用个动画

按钮样式

  1. <Style x:Key="LeftShowAndHideToggleButtonStyle" TargetType="ToggleButton">
  2. <Setter Property="Template">
  3. <Setter.Value>
  4. <ControlTemplate TargetType="ToggleButton">
  5. <Grid x:Name="grid">
  6. <VisualStateManager.VisualStateGroups>
  7. <VisualStateGroup x:Name="CheckStates">
  8. <VisualState x:Name="Checked"/>
  9. <VisualState x:Name="Unchecked">
  10. <Storyboard>
  11. <DoubleAnimation Duration="0" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" Storyboard.TargetName="Flexible_arrow"/>
  12. </Storyboard>
  13. </VisualState>
  14. <VisualState x:Name="Indeterminate"/>
  15. </VisualStateGroup>
  16. <VisualStateGroup x:Name="CommonStates">
  17. <VisualState x:Name="Normal"/>
  18. <VisualState x:Name="MouseOver">
  19. <Storyboard>
  20. <ColorAnimation Duration="0" To="#FF25418D" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="path"/>
  21. <ColorAnimation Duration="0" To="#FF4179C2" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="path"/>
  22. <ColorAnimation Duration="0" To="#FF5EB2F8" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="path"/>
  23. <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Cursor)" Storyboard.TargetName="grid">
  24. <DiscreteObjectKeyFrame KeyTime="0">
  25. <DiscreteObjectKeyFrame.Value>
  26. <Cursor>Hand</Cursor>
  27. </DiscreteObjectKeyFrame.Value>
  28. </DiscreteObjectKeyFrame>
  29. </ObjectAnimationUsingKeyFrames>
  30. </Storyboard>
  31. </VisualState>
  32. <VisualState x:Name="Pressed"/>
  33. <VisualState x:Name="Disabled"/>
  34. </VisualStateGroup>
  35. </VisualStateManager.VisualStateGroups>
  36. <Path x:Name="path" Stretch="Fill" Data="F1 M 1131.5,311.621L 1131.5,311.621C 1133.15,311.621 1134.5,312.964 1134.5,314.621L 1134.5,504.621C 1134.5,506.278 1133.15,507.621 1131.5,507.621L 1131.5,507.621C 1129.84,507.621 1128.5,506.278 1128.5,504.621L 1128.5,314.621C 1128.5,312.964 1129.84,311.621 1131.5,311.621 Z ">
  37. <Path.Fill>
  38. <LinearGradientBrush StartPoint="-2.03455e-005,0.5" EndPoint="1,0.5">
  39. <GradientStop Color="#B325418D" Offset="0.231481"/>
  40. <GradientStop Color="#B34179C2" Offset="0.680556"/>
  41. <GradientStop Color="#B35EB2F8" Offset="1"/>
  42. </LinearGradientBrush>
  43. </Path.Fill>
  44. </Path>
  45. <Path x:Name="Flexible_arrow" Stretch="Fill" Fill="#CDFFFFFF" Data="F1 M 1133.47,408.839L 1130.43,411.621L 1130.43,406.058L 1133.47,408.839 Z " HorizontalAlignment="Center" VerticalAlignment="Center" Width="3" Height="6" RenderTransformOrigin="0.5,0.5">
  46. <Path.RenderTransform>
  47. <RotateTransform />
  48. </Path.RenderTransform>
  49. </Path>
  50. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  51. </Grid>
  52. </ControlTemplate>
  53. </Setter.Value>
  54. </Setter>
  55. </Style>

 

布局代码

  1. <Grid x:Name="LayoutRoot">
  2. <Grid.ColumnDefinitions>
  3. <ColumnDefinition Width="Auto"/>
  4. <ColumnDefinition Width="8"/>
  5. </Grid.ColumnDefinitions>
  6. <Grid x:Name="treeViewGrid" Width="222">
  7. <TreeView x:Name="treeView" Style="{StaticResource MenuTreeView}" ItemsSource="{Binding ItemTreeDataList}" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" SelectedItemChanged="treeView_SelectedItemChanged" >
  8. <TreeView.ItemTemplate>
  9. <HierarchicalDataTemplate ItemsSource="{Binding Children}">
  10. <TextBlock x:Name="treeViewItemTB" Text="{Binding itemName}" Tag="{Binding itemId}"/>
  11. </HierarchicalDataTemplate>
  12. </TreeView.ItemTemplate>
  13. </TreeView>
  14. </Grid>
  15. <Grid Grid.Column="1" Margin="0">
  16. <ToggleButton Style="{StaticResource LeftShowAndHideToggleButtonStyle}" Margin="0,0,0,0" x:Name="menuBtn" Width="8" Height="50" Click="menuBtn_Click">
  17. </ToggleButton>
  18. </Grid>
  19. </Grid>

按钮点击

  1. private void menuBtn_Click(object sender, RoutedEventArgs e)
  2. {
  3. if ((sender as ToggleButton).IsChecked.Value)
  4. {
  5. Storyboard sbHide = this.Resources["sb_HideRightPart"] as Storyboard;
  6. if (sbHide != null)
  7. sbHide.Begin();
  8. }
  9. else
  10. {
  11. Storyboard sbHide = this.Resources["sb_ShowRightPart"] as Storyboard;
  12. if (sbHide != null)
  13. sbHide.Begin();
  14. }
  15. }

Storyboard 代码

  1. <Storyboard x:Name="sb_HideRightPart" x:Key="sb_HideRightPart" FillBehavior="HoldEnd">
  2. <DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="treeViewGrid" d:IsOptimized="True"/>
  3. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="treeViewGrid">
  4. <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="222"/>
  5. <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="0"/>
  6. </DoubleAnimationUsingKeyFrames>
  7. </Storyboard>
  8. <Storyboard x:Name="sb_ShowRightPart" x:Key="sb_ShowRightPart" FillBehavior="HoldEnd">
  9. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="treeViewGrid">
  10. <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
  11. <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="222"/>
  12. </DoubleAnimationUsingKeyFrames>
  13. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="treeViewGrid">
  14. <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
  15. <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
  16. <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="1"/>
  17. </DoubleAnimationUsingKeyFrames>
  18. </Storyboard>

 

Prism for WPF 搭建一个简单的模块化开发框架(六)隐藏菜单、导航的更多相关文章

  1. Prism for WPF 搭建一个简单的模块化开发框架 (一个节点)

    原文:Prism for WPF 搭建一个简单的模块化开发框架 (一个节点) 这里我就只贴图不贴代码了,看看这个节点之前的效果 觉得做的好的地方可以范之前的文章看看 有好的建议也可以说说   填充数据 ...

  2. Prism for WPF 搭建一个简单的模块化开发框架(四)异步调用WCF服务、WCF消息头添加安全验证Token

    原文:Prism for WPF 搭建一个简单的模块化开发框架(四)异步调用WCF服务.WCF消息头添加安全验证Token 为什么选择wcf?   因为好像wcf和wpf就是哥俩,,, 为什么选择异步 ...

  3. Prism for WPF 搭建一个简单的模块化开发框架(五)添加聊天、消息模块

    原文:Prism for WPF 搭建一个简单的模块化开发框架(五)添加聊天.消息模块 中秋节假期没事继续搞了搞 做了各聊天的模块,需要继续优化 第一步画页面 页面参考https://github.c ...

  4. Prism for WPF 搭建一个简单的模块化开发框架(三) 给TreeView加样式做成菜单

    原文:Prism for WPF 搭建一个简单的模块化开发框架(三) 给TreeView加样式做成菜单 昨天晚上把TreeView的样式做了一下,今天给TreeView绑了数据,实现了切换页面功能 上 ...

  5. Prism for WPF 搭建一个简单的模块化开发框架(二)

    原文:Prism for WPF 搭建一个简单的模块化开发框架(二) 今天又有时间了,再改改,加了一些控件全局的样式 样式代码 <ResourceDictionary xmlns="h ...

  6. Prism for WPF 搭建一个简单的模块化开发框架(一)

    原文:Prism for WPF 搭建一个简单的模块化开发框架(一) 最近闲来无事又想搞搞WPF..... 做个框架吧,可能又是半途而废....总是坚持不下来 不废话了, 先看一下工程结构 布局大概是 ...

  7. 用express搭建一个简单的博客系统

    转自:https://blog.csdn.net/qq_29721837/article/details/62055603 Express 简介 Express 是一个简洁而灵活的 node.js W ...

  8. 从零开始搭建一个简单的基于webpack的vue开发环境

    原文地址:https://segmentfault.com/a/1190000012789253?utm_source=tag-newest 从零开始搭建一个简单的基于webpack的react开发环 ...

  9. 用nodejs搭建一个简单的服务器

    使用nodejs搭建一个简单的服务器 nodejs优点:性能高(读写文件) 数据操作能力强 官网:www.nodejs.org 验证是否安装成功:cmd命令行中输入node -v 如果显示版本号表示安 ...

随机推荐

  1. 50. Pow(x, n) (recursion)

    Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Ou ...

  2. Mysql优化实践(分页优化)

    当你和别人都能实现一个某个功能,这时候区分你们能力的不是谁干活多少,而是谁能写出效率更高的代码.比如显示一个订单列表它不仅仅是写一条SELECT SQL那么简单,我们还需要很清楚的知道这条SQL他大概 ...

  3. ASP.NET SingalR 点对点聊天实现思路总结

    前一段时间写了一个简单的聊天室,是群聊的方式.博客地址:http://www.cnblogs.com/panzi/p/4980346.html.还有一种需求就是常见的尤其是培训机构的主页面,经常会有1 ...

  4. IP黑白名单

    防攻击可以增加IP白名单/etc/hosts.allow和黑名单/etc/hosts.deny /etc/hosts.allow  IP白名单 /etc/hosts.deny   IP黑名单 /etc ...

  5. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  6. C# 类中的静态字段始终继承自基类

    我们试想一下现在有一个类Parent,它有一个static的int类型字段number,然后如果类Parent有三个子类Child01.Child02和Child03,那么改变Parent.numbe ...

  7. Java基础随笔3

    一. 键盘录入数据概述 我们目前在写程序的时候,数据值都是固定的,但是实际开发中,数据值肯定是变化的,所以,把数据改进为键盘录入,提高程序的灵活性. 键盘录入数据的步骤: A:导包(位置放到class ...

  8. SQLServer如何批量替换某一列中的某个字符串

    我们在开发系统的时候经常会碰到类似如下这样的情况:比如我有一张数据表 假如我现在要把红圈中这列的的http://www.mylanqiu.com/ 这个字符串批量替换成mylanqiu 这个字符串,这 ...

  9. 使用Kubespray部署Kubernetes集群

    转载请标明出处: http://blog.csdn.net/forezp/article/details/82730382 本文出自方志朋的博客 Kubespray是Google开源的一个部署生产级别 ...

  10. Linux -- date 日期命令

    Linux -- date 日期命令 date 用法:date [选项]... [+格式] 以给定的格式显示当前时间,或是设置系统日期. 1.使用 date 命令查看当前日期或当前时间 [root@l ...