食品商务网-网站建设,有edi证书可以做网站运营么,报考建设八大员官方网站,厦门茶叶公司 网站建设文章目录 1、案例效果1、侧边栏分类2、AB类侧边弹窗实现1.文件创建2、样式代码与功能代码实现3、功能代码实现 3 运行效果4、源代码获取 1、案例效果 1、侧边栏分类
A类 #xff1a;左侧弹出侧边栏B类 #xff1a;右侧弹出侧边栏C类 #xff1a;顶部弹出侧边栏D类 #xf… 文章目录 1、案例效果1、侧边栏分类2、AB类侧边弹窗实现1.文件创建2、样式代码与功能代码实现3、功能代码实现 3 运行效果4、源代码获取 1、案例效果 1、侧边栏分类
A类 左侧弹出侧边栏B类 右侧弹出侧边栏C类 顶部弹出侧边栏D类 底部弹出侧边栏
2、AB类侧边弹窗实现
1.文件创建
打开项目 Wpf_Examples ,在Views 文件夹下创建窗体界面文件 PopPanelWindow.xaml 。如下所示
2、样式代码与功能代码实现
1、弹出床的两种实现一种是鼠标移上按钮就触发点击弹窗面板关闭效果。第二种是 单击按钮弹出侧边栏鼠标点击其他空白区域退出弹窗栏。这里我们把第一种做成右侧弹出栏第二种做成左侧弹出栏。
PopPanelWindow.xaml 界面样式如下所示
Window x:ClassWpf_Examples.Views.PopPanelWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:Wpf_Examples.Viewsmc:IgnorabledTitlePopPanelWindow Height450 Width600 Background#2B2B2BGridButton Width250 Height30 Content鼠标移上按弹出右侧边栏Button.Triggers!-- 用按钮的鼠标进入事件来触发进入动画 --EventTrigger RoutedEventMouseEnterBeginStoryboard!-- 进入动画 --Storyboard Storyboard.TargetNameborder Storyboard.TargetPropertyRenderTransform.XDoubleAnimation From120To0Duration0:0:1DoubleAnimation.EasingFunction!-- 设置缓动模式和振荡次数 --BackEase Amplitude0.5 EasingModeEaseOut //DoubleAnimation.EasingFunction/DoubleAnimation/Storyboard/BeginStoryboard/EventTrigger/Button.Triggers/Button!-- 侧边栏 --Border x:NameborderWidth200HorizontalAlignmentRightBackgroundLightSkyBlue!--位移效果-- Border.RenderTransformTranslateTransform x:Namett X200 //Border.RenderTransformBorder.EffectDropShadowEffect Direction205Opacity0.6ShadowDepth1ColorBlack //Border.EffectBorder.Triggers!-- 鼠标的左键按下事件来触发退出动画 --EventTrigger RoutedEventMouseLeftButtonDownBeginStoryboard!-- 退出动画 --Storyboard Storyboard.TargetNamett Storyboard.TargetPropertyXDoubleAnimation From0To200Duration0:0:0.8 //Storyboard/BeginStoryboard/EventTrigger/Border.Triggers/BorderButton Width150 Height30 Margin0 80 0 0 Content单击弹出左侧侧边栏 ClickButton_Click/!-- 左侧边栏 --Border x:NameleftPanelWidth200HorizontalAlignmentLeftBackgroundLightSkyBlueVisibilityCollapsed!-- 位移效果 --Border.RenderTransformTranslateTransform x:NametoRight X0 //Border.RenderTransformBorder.EffectDropShadowEffect Direction225 Opacity0.6 ShadowDepth1 ColorBlack //Border.Effect/Border/Grid
/Window
3、功能代码实现
PopPanelWindow.cs 按钮事件代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;namespace Wpf_Examples.Views
{/// summary/// PopPanelWindow.xaml 的交互逻辑/// /summarypublic partial class PopPanelWindow : Window{public PopPanelWindow(){InitializeComponent();// 注册窗口的鼠标点击事件this.MouseLeftButtonDown PopPanelWindow_MouseLeftButtonDown;}private void Button_Click(object sender, RoutedEventArgs e){// 触发进入动画leftPanel.Visibility Visibility.Visible;Storyboard enterStoryboard new Storyboard();DoubleAnimation enterAnimation new DoubleAnimation{From 0,To 200,Duration TimeSpan.FromSeconds(1),EasingFunction new BackEase { Amplitude 0.5, EasingMode EasingMode.EaseOut }};Storyboard.SetTarget(enterAnimation, toRight);Storyboard.SetTargetProperty(enterAnimation, new PropertyPath(X));enterStoryboard.Children.Add(enterAnimation);enterStoryboard.Begin();}private void PopPanelWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){// 检查点击的位置是否在侧边栏之外if (!leftPanel.IsMouseOver leftPanel.Visibility Visibility.Visible){// 触发退出动画Storyboard exitStoryboard new Storyboard();DoubleAnimation exitAnimation new DoubleAnimation{From 200,To 0,Duration TimeSpan.FromSeconds(0.6)};Storyboard.SetTarget(exitAnimation, toRight);Storyboard.SetTargetProperty(exitAnimation, new PropertyPath(X));exitStoryboard.Children.Add(exitAnimation);exitStoryboard.Completed (s, ev) leftPanel.Visibility Visibility.Collapsed;exitStoryboard.Begin();}}}
}
3 运行效果 4、源代码获取
源代码是包含上下左右侧边弹出栏全部功能的。代码下载后直接运行即可。 CSDN下载链接WPF实战案例系列-侧边弹窗等案例