中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

億唐網(wǎng)不做網(wǎng)站做品牌考試題中國互聯(lián)網(wǎng)公司排名

億唐網(wǎng)不做網(wǎng)站做品牌考試題,中國互聯(lián)網(wǎng)公司排名,下載軟件的網(wǎng)站,杭州怎樣建設(shè)網(wǎng)站W(wǎng)PF實現(xiàn)一個帶旋轉(zhuǎn)動畫的菜單欄 一、創(chuàng)建WPF項目及文件1、創(chuàng)建項目2、創(chuàng)建文件夾及文件3、添加引用 二、代碼實現(xiàn)2.ControlAttachProperty類 一、創(chuàng)建WPF項目及文件 1、創(chuàng)建項目 打開VS2022,創(chuàng)建一個WPF項目,如下所示 2、創(chuàng)建文件夾及文件 創(chuàng)建資源文件夾&…

WPF實現(xiàn)一個帶旋轉(zhuǎn)動畫的菜單欄

  • 一、創(chuàng)建WPF項目及文件
    • 1、創(chuàng)建項目
    • 2、創(chuàng)建文件夾及文件
    • 3、添加引用
  • 二、代碼實現(xiàn)
    • 2.ControlAttachProperty類

一、創(chuàng)建WPF項目及文件

1、創(chuàng)建項目

打開VS2022,創(chuàng)建一個WPF項目,如下所示
在這里插入圖片描述在這里插入圖片描述

2、創(chuàng)建文件夾及文件

創(chuàng)建資源文件夾,添加字體圖標(biāo)文件,添加 Menu樣式文件,如下所示
在這里插入圖片描述
創(chuàng)建公共附加屬性用控件類庫,并創(chuàng)建對應(yīng)的 ControlAttachProperty 類文件如下:
在這里插入圖片描述
在這里插入圖片描述

3、添加引用

右鍵 Menu_WPF 添加引用,將類庫引用到當(dāng)前項目
在這里插入圖片描述

二、代碼實現(xiàn)

2.ControlAttachProperty類

代碼如下(示例):

using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using CheckBox = System.Windows.Controls.CheckBox;
using ComboBox = System.Windows.Controls.ComboBox;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
using RadioButton = System.Windows.Controls.RadioButton;
using RichTextBox = System.Windows.Controls.RichTextBox;
using TextBox = System.Windows.Controls.TextBox;namespace Common.UserControl.Extession
{/// <summary>/// 公共附加屬性/// </summary>public static class ControlAttachProperty{#region FocusBorderBrush 焦點邊框色,輸入控件public static readonly DependencyProperty FocusBorderBrushProperty = DependencyProperty.RegisterAttached("FocusBorderBrush", typeof(Brush), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));public static void SetFocusBorderBrush(DependencyObject element, Brush value){element.SetValue(FocusBorderBrushProperty, value);}public static Brush GetFocusBorderBrush(DependencyObject element){return (Brush)element.GetValue(FocusBorderBrushProperty);}#endregion#region MouseOverBorderBrush 鼠標(biāo)進入邊框色,輸入控件public static readonly DependencyProperty MouseOverBorderBrushProperty =DependencyProperty.RegisterAttached("MouseOverBorderBrush", typeof(Brush), typeof(ControlAttachProperty),new FrameworkPropertyMetadata(Brushes.Transparent,FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));/// <summary>/// Sets the brush used to draw the mouse over brush./// </summary>public static void SetMouseOverBorderBrush(DependencyObject obj, Brush value){obj.SetValue(MouseOverBorderBrushProperty, value);}/// <summary>/// Gets the brush used to draw the mouse over brush./// </summary>[AttachedPropertyBrowsableForType(typeof(TextBox))][AttachedPropertyBrowsableForType(typeof(CheckBox))][AttachedPropertyBrowsableForType(typeof(RadioButton))][AttachedPropertyBrowsableForType(typeof(DatePicker))][AttachedPropertyBrowsableForType(typeof(ComboBox))][AttachedPropertyBrowsableForType(typeof(RichTextBox))]public static Brush GetMouseOverBorderBrush(DependencyObject obj){return (Brush)obj.GetValue(MouseOverBorderBrushProperty);}#endregion#region AttachContentProperty 附加組件模板/// <summary>/// 附加組件模板/// </summary>public static readonly DependencyProperty AttachContentProperty = DependencyProperty.RegisterAttached("AttachContent", typeof(ControlTemplate), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));public static ControlTemplate GetAttachContent(DependencyObject d){return (ControlTemplate)d.GetValue(AttachContentProperty);}public static void SetAttachContent(DependencyObject obj, ControlTemplate value){obj.SetValue(AttachContentProperty, value);}#endregion#region WatermarkProperty 水印/// <summary>/// 水印/// </summary>public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached("Watermark", typeof(string), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(""));public static string GetWatermark(DependencyObject d){return (string)d.GetValue(WatermarkProperty);}public static void SetWatermark(DependencyObject obj, string value){obj.SetValue(WatermarkProperty, value);}#endregion#region FIconProperty 字體圖標(biāo)/// <summary>/// 字體圖標(biāo)/// </summary>public static readonly DependencyProperty FIconProperty = DependencyProperty.RegisterAttached("FIcon", typeof(string), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(""));public static string GetFIcon(DependencyObject d){return (string)d.GetValue(FIconProperty);}public static void SetFIcon(DependencyObject obj, string value){obj.SetValue(FIconProperty, value);}#endregion#region FIconSizeProperty 字體圖標(biāo)大小/// <summary>/// 字體圖標(biāo)/// </summary>public static readonly DependencyProperty FIconSizeProperty = DependencyProperty.RegisterAttached("FIconSize", typeof(double), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(12D));public static double GetFIconSize(DependencyObject d){return (double)d.GetValue(FIconSizeProperty);}public static void SetFIconSize(DependencyObject obj, double value){obj.SetValue(FIconSizeProperty, value);}#endregion#region FIconMarginProperty 字體圖標(biāo)邊距/// <summary>/// 字體圖標(biāo)/// </summary>public static readonly DependencyProperty FIconMarginProperty = DependencyProperty.RegisterAttached("FIconMargin", typeof(Thickness), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));public static Thickness GetFIconMargin(DependencyObject d){return (Thickness)d.GetValue(FIconMarginProperty);}public static void SetFIconMargin(DependencyObject obj, Thickness value){obj.SetValue(FIconMarginProperty, value);}#endregion#region AllowsAnimationProperty 啟用旋轉(zhuǎn)動畫/// <summary>/// 啟用旋轉(zhuǎn)動畫/// </summary>public static readonly DependencyProperty AllowsAnimationProperty = DependencyProperty.RegisterAttached("AllowsAnimation", typeof(bool), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(false, AllowsAnimationChanged));public static bool GetAllowsAnimation(DependencyObject d){return (bool)d.GetValue(AllowsAnimationProperty);}public static void SetAllowsAnimation(DependencyObject obj, bool value){obj.SetValue(AllowsAnimationProperty, value);}/// <summary>/// 旋轉(zhuǎn)動畫刻度/// </summary>private static DoubleAnimation RotateAnimation = new DoubleAnimation(0, new Duration(TimeSpan.FromMilliseconds(200)));/// <summary>/// 綁定動畫事件/// </summary>private static void AllowsAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){var uc = d as FrameworkElement;if (uc == null) return;if (uc.RenderTransformOrigin == new Point(0, 0)){uc.RenderTransformOrigin = new Point(0.5, 0.5);RotateTransform trans = new RotateTransform(0);uc.RenderTransform = trans;}var value = (bool)e.NewValue;if (value){RotateAnimation.To = 180;uc.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, RotateAnimation);}else{RotateAnimation.To = 0;uc.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, RotateAnimation);}}#endregion#region CornerRadiusProperty Border圓角/// <summary>/// Border圓角/// </summary>public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached("CornerRadius", typeof(CornerRadius), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));public static CornerRadius GetCornerRadius(DependencyObject d){return (CornerRadius)d.GetValue(CornerRadiusProperty);}public static void SetCornerRadius(DependencyObject obj, CornerRadius value){obj.SetValue(CornerRadiusProperty, value);}#endregion#region LabelProperty TextBox的頭部Label/// <summary>/// TextBox的頭部Label/// </summary>public static readonly DependencyProperty LabelProperty = DependencyProperty.RegisterAttached("Label", typeof(string), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));[AttachedPropertyBrowsableForType(typeof(TextBox))]public static string GetLabel(DependencyObject d){return (string)d.GetValue(LabelProperty);}public static void SetLabel(DependencyObject obj, string value){obj.SetValue(LabelProperty, value);}#endregion#region LabelTemplateProperty TextBox的頭部Label模板/// <summary>/// TextBox的頭部Label模板/// </summary>public static readonly DependencyProperty LabelTemplateProperty = DependencyProperty.RegisterAttached("LabelTemplate", typeof(ControlTemplate), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));[AttachedPropertyBrowsableForType(typeof(TextBox))]public static ControlTemplate GetLabelTemplate(DependencyObject d){return (ControlTemplate)d.GetValue(LabelTemplateProperty);}public static void SetLabelTemplate(DependencyObject obj, ControlTemplate value){obj.SetValue(LabelTemplateProperty, value);}#endregion}
}

Menu樣式文件實現(xiàn)

    <!--背景透明的HeaderItem樣式,帶旋轉(zhuǎn)動畫--><Style x:Key="TransparentHeaderMenuItem" TargetType="{x:Type MenuItem}"><Setter Property="BorderBrush" Value="{StaticResource MenuBorderBrush}"/><Setter Property="BorderThickness" Value="1"/><Setter Property="Background" Value="{StaticResource MenuBackground}"/><Setter Property="Foreground" Value="{StaticResource TextForeground}"/><Setter Property="FontSize" Value="{StaticResource FontSize}"/><Setter Property="Margin" Value="2,0,2,0"/><Setter Property="Height" Value="30"/><Setter Property="local:ControlAttachProperty.FIconSize" Value="18"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type MenuItem}"><Grid x:Name="Bg" VerticalAlignment="{TemplateBinding VerticalAlignment}"><StackPanel Orientation="Horizontal" x:Name="border" VerticalAlignment="Center" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"><!--icon--><TextBlock x:Name="PART_Icon" Text="{TemplateBinding Icon}" Foreground="{TemplateBinding Foreground}" local:ControlAttachProperty.AllowsAnimation="{Binding IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}"FontSize="{TemplateBinding local:ControlAttachProperty.FIconSize}" Style="{StaticResource FIcon}" /><TextBlock x:Name="txtHeader" Margin="5 0 0 0" FontSize="{TemplateBinding FontSize}" HorizontalAlignment="Stretch" Text="{TemplateBinding Header}" VerticalAlignment="Center" Grid.Column="1" Foreground="{TemplateBinding Foreground}"/></StackPanel><!--彈出子集菜單容器--><Popup x:Name="SubMenuPopup" AllowsTransparency="true" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom"  Focusable="false" VerticalOffset="0"PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"><Border Background="{TemplateBinding Background}"  CornerRadius="0" Margin="5" Effect="{StaticResource DefaultDropShadow}"BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"><Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True"><StackPanel Margin="10" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/></Grid></Border></Popup></Grid><!--觸發(fā)器--><ControlTemplate.Triggers><!--高亮狀態(tài)--><Trigger Property="IsHighlighted" Value="true"><Setter Property="Foreground" Value="{StaticResource MouseOverForeground}"></Setter></Trigger><Trigger Property="IsPressed" Value="true"><Setter Property="Foreground" Value="{StaticResource PressedForeground}"></Setter></Trigger><Trigger Property="IsEnabled" Value="False"><Setter TargetName="border" Value="{StaticResource DisableOpacity}" Property="Opacity"></Setter></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

MainWindow樣式實現(xiàn)

  <Menu Width="80" Height="30" Margin="3" Background="Transparent" ><MenuItem Header="展開菜單" Style="{StaticResource TransparentHeaderMenuItem}" Padding="0" Icon="&#xe61b;" ><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe605;" Header="設(shè)置" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe656;" Header="插件管理" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe65e;"  Header="用戶管理" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe659;" Header="修改密碼" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe7c6;" Header="在線更新" /><Separator Background="SpringGreen" Style="{StaticResource HorizontalSeparatorStyle}"/><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe6d5;" Header="問題反饋" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe65f;" Header="技術(shù)支持" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe600;" Header="幫助" /><MenuItem Style="{StaticResource TransparentHeaderMenuItem}" Icon="&#xe622;" Header="關(guān)于" /></MenuItem></Menu>
http://www.risenshineclean.com/news/58629.html

相關(guān)文章:

  • 哪里有專業(yè)做網(wǎng)站國內(nèi)最新新聞事件今天
  • 大學(xué)生做企業(yè)網(wǎng)站東莞關(guān)鍵詞優(yōu)化平臺
  • 怎么做博客網(wǎng)站上海網(wǎng)絡(luò)seo
  • 網(wǎng)站如何做微信支付寶支付寶支付近期國家新聞
  • 動態(tài)網(wǎng)站作業(yè)建網(wǎng)站不花錢免費建站
  • 寶塔面板怎么做網(wǎng)站中國市場營銷網(wǎng)網(wǎng)站
  • 深圳龍華建設(shè)工程交易中心網(wǎng)站本溪seo優(yōu)化
  • 轉(zhuǎn)移網(wǎng)站如何轉(zhuǎn)數(shù)據(jù)庫百度知道答題賺錢
  • 常州企業(yè)網(wǎng)站建設(shè)價格網(wǎng)站優(yōu)化關(guān)鍵詞排名
  • 政府網(wǎng)站建設(shè)被問責(zé)怎么讓網(wǎng)站快速收錄
  • 福州做網(wǎng)站的公seo分析工具有哪些
  • 中山哪里做網(wǎng)站seo職業(yè)培訓(xùn)班
  • 邯鄲網(wǎng)站設(shè)計招聘最新域名查詢
  • 公眾號視頻網(wǎng)站開發(fā)微博營銷成功案例8個
  • 怎么讓網(wǎng)站欄目頁收錄廣州公司關(guān)鍵詞網(wǎng)絡(luò)推廣
  • 企業(yè)商務(wù)網(wǎng)站建設(shè)策劃書優(yōu)化網(wǎng)站首頁
  • 播視頻網(wǎng)站開發(fā)網(wǎng)站外鏈查詢
  • 做網(wǎng)站找哪家好熊掌號英文關(guān)鍵詞seo
  • 做視頻網(wǎng)站需要什么空間視頻號直播推廣二維碼
  • 微信如何做積分商城網(wǎng)站網(wǎng)站seo關(guān)鍵詞優(yōu)化排名
  • 番禺seo培訓(xùn)如何優(yōu)化關(guān)鍵詞的排名
  • wordpress交互主題揭陽seo快速排名
  • 設(shè)計門戶網(wǎng)百度seo競價推廣是什么
  • 做b2b比較好的網(wǎng)站seo零基礎(chǔ)入門教程
  • axure做網(wǎng)站教學(xué)視頻寧海關(guān)鍵詞優(yōu)化怎么優(yōu)化
  • 杭州做企業(yè)網(wǎng)站公司seo前線
  • 織夢網(wǎng)站需要付費嗎百度搜首頁
  • 許昌那有做網(wǎng)站網(wǎng)頁點擊量統(tǒng)計
  • 廣州做網(wǎng)站最好的公司深圳seo公司排名
  • php 建設(shè)網(wǎng)站網(wǎng)站老域名跳轉(zhuǎn)到新域名