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

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

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

 

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

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

按钮样式

 <Style x:Key="LeftShowAndHideToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid x:Name="grid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked"/>
<VisualState x:Name="Unchecked">
<Storyboard>
<DoubleAnimation Duration="0" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" Storyboard.TargetName="Flexible_arrow"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Indeterminate"/>
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="0" To="#FF25418D" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="path"/>
<ColorAnimation Duration="0" To="#FF4179C2" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="path"/>
<ColorAnimation Duration="0" To="#FF5EB2F8" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="path"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Cursor)" Storyboard.TargetName="grid">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Cursor>Hand</Cursor>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<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 ">
<Path.Fill>
<LinearGradientBrush StartPoint="-2.03455e-005,0.5" EndPoint="1,0.5">
<GradientStop Color="#B325418D" Offset="0.231481"/>
<GradientStop Color="#B34179C2" Offset="0.680556"/>
<GradientStop Color="#B35EB2F8" Offset="1"/>
</LinearGradientBrush>
</Path.Fill>
</Path>
<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">
<Path.RenderTransform>
<RotateTransform />
</Path.RenderTransform>
</Path>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

 

布局代码

<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="8"/>
</Grid.ColumnDefinitions>
<Grid x:Name="treeViewGrid" Width="222">
<TreeView x:Name="treeView" Style="{StaticResource MenuTreeView}" ItemsSource="{Binding ItemTreeDataList}" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" SelectedItemChanged="treeView_SelectedItemChanged" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock x:Name="treeViewItemTB" Text="{Binding itemName}" Tag="{Binding itemId}"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
<Grid Grid.Column="1" Margin="0">
<ToggleButton Style="{StaticResource LeftShowAndHideToggleButtonStyle}" Margin="0,0,0,0" x:Name="menuBtn" Width="8" Height="50" Click="menuBtn_Click">
</ToggleButton>
</Grid>
</Grid>

按钮点击

private void menuBtn_Click(object sender, RoutedEventArgs e)
{
if ((sender as ToggleButton).IsChecked.Value)
{
Storyboard sbHide = this.Resources["sb_HideRightPart"] as Storyboard;
if (sbHide != null)
sbHide.Begin();
}
else
{
Storyboard sbHide = this.Resources["sb_ShowRightPart"] as Storyboard;
if (sbHide != null)
sbHide.Begin();
}
}

Storyboard 代码

 <Storyboard x:Name="sb_HideRightPart" x:Key="sb_HideRightPart" FillBehavior="HoldEnd">
<DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="treeViewGrid" d:IsOptimized="True"/>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="treeViewGrid">
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="222"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="sb_ShowRightPart" x:Key="sb_ShowRightPart" FillBehavior="HoldEnd">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="treeViewGrid">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="222"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="treeViewGrid">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</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. February 22 2017 Week 8 Wednesday

    There is only one happiness in life, to love and be loved. 生命中只有一种幸福,爱与被爱. If you think you are not ...

  2. Go语言(三)反射机制

    package main import( "fmt" "reflect" ) func main(){ // iterate through the attri ...

  3. 在自己机器上实现apache的多域名

    自己机器上有3个目录,分别是/var/www/html/                             /var/www/solaris/                           ...

  4. Promise里捕捉错误的最佳实践

    Promise里的同步部分不需要try catch new Promise((resolve, reject) => { throw new Error('error'); setTimeout ...

  5. Eclipse Ctrl + Shift + O in IntelliJ IDEA

    In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For Inte ...

  6. 有趣的IntegerCache

    一个很有趣的现象,下面这两个结果输出的结果是false true,这是为什么?   翻看Integer的源码可以看到,当new Integer(12);时,没有什么特别的,就是通过构造方法创建了一个I ...

  7. bzoj4600 [Sdoi2016]硬币游戏

    Description Alice和Bob现在在玩的游戏,主角是依次编号为1到n的n枚硬币.每一枚硬币都有两面,我们分别称之为正面和反面.一开始的时候,有些硬币是正面向上的,有些是反面朝上的.Alic ...

  8. HandyJSON代码阅读

    功能:model = modelType.transform(rawdata) 使用分析: 使用机制:继承+实现配置+使用: 需要自己实现什么? 设计分析: 工具模块?机制模块?model基类? 生成 ...

  9. sql时间格式转换

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...

  10. 通过nginx 499 来判断服务端超时数量

    这个其实不能算一篇文章,因为内容太少了,就当记点笔记吧. (1)什么是 nginx 499 499 其实是 nginx 下特有的 http 状态码,代表客户端主动断开了连接,导致服务器无法返回 htt ...