WPF实现实现圆形菜单

WPF开发者QQ群: 340500857 

有小伙伴需要实现圆形菜单。

效果如下:

一、Xaml代码如下

<Window x:Class="WpfRoundMenu.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfRoundMenu"mc:Ignorable="d"Title="MainWindow" Height="400" Width="400" ResizeMode="NoResize" Background="{x:Null}" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True"><Window.Resources><Style x:Key="ButtonMenu" TargetType="Button"><Setter Property= "Opacity" Value="0.8"/><Setter Property="Cursor" Value ="Hand"/><Setter Property="Template"><Setter.Value><ControlTemplate><Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"OpacityMask="{TemplateBinding OpacityMask}"/><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Opacity" Value="1"/></Trigger><Trigger Property="IsEnabled" Value= "False"><Setter Property="Opacity" Value="0.3"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter>
</Style></Window.Resources><Grid><Grid x:Name="gMenu" MouseDown="gMenu_MouseDown"><Grid.Background><RadialGradientBrush><GradientStop Color="White" Offset="0.9"/><GradientStop Offset="1"/><GradientStop x:Name="ColoCirkle" Color="#7F434343" Offset="0.91"/></RadialGradientBrush></Grid.Background><Grid.RowDefinitions><RowDefinition Height="1*"/><RowDefinition Height="1*"/><RowDefinition Height="1*"/><RowDefinition Height="1*"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="1*"/><ColumnDefinition Width="1*"/><ColumnDefinition Width="1*"/><ColumnDefinition Width="1*"/></Grid.ColumnDefinitions><Button x:Name="btn1" Foreground="{x:Null}" BorderBrush="#FF009AD6" Background="#FF716E6E" Style="{StaticResource ButtonMenu}" Grid.ColumnSpan="2" Margin="68,35,66,0" Grid.Column="1" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"><Button.OpacityMask><ImageBrush ImageSource="Images/Color.png"/></Button.OpacityMask></Button><Button x:Name="btn2" Foreground="{x:Null}" BorderBrush="#FF007642" Background="#FF6E7170" Style="{StaticResource ButtonMenu}" Margin="0,64,34,67" Grid.Column="3" Grid.Row="1" Grid.RowSpan="2" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"><Button.OpacityMask><ImageBrush ImageSource="Images/Eraser.png"/></Button.OpacityMask></Button><Button x:Name="btn3" Foreground="{x:Null}" BorderBrush="#FF656097" Background="#FF716E6E" Style="{StaticResource ButtonMenu}" Margin="68,0,66,46" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="2" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"><Button.OpacityMask><ImageBrush ImageSource="Images/Revoke.png"/></Button.OpacityMask></Button><Button x:Name="btn4" Foreground="{x:Null}" BorderBrush="#FFEE73CC" Background="#FF716E6E" Style="{StaticResource ButtonMenu}" Margin="34,64,0,67" Grid.Row="1" Grid.RowSpan="2" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"><Button.OpacityMask><ImageBrush ImageSource="Images/Pen.png"/></Button.OpacityMask></Button><Grid x:Name="gClose" Grid.ColumnSpan="2" Grid.Column="1" Margin="20,21,19,20" Grid.Row="1" Grid.RowSpan="2"><Grid.Background><RadialGradientBrush><GradientStop Color="#FFE7E7E7" Offset="0.854"/><GradientStop Offset="1"/><GradientStop Color="#FFBCBCBC" Offset="0.856"/></RadialGradientBrush></Grid.Background><Button Margin="58,59,59,52" x:Name="btn5" Foreground="{x:Null}" BorderBrush="#FFFF6B6B" Background="#FF716E6E" Style="{StaticResource ButtonMenu}"MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"><Button.OpacityMask><ImageBrush ImageSource="Images/Close.png"/></Button.OpacityMask></Button></Grid></Grid></Grid>
</Window>

二、Xaml.cs代码如下

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;namespace WpfRoundMenu
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}Storyboard storyboard;ColorAnimation SetAnimButton(Color color,string objName){ColorAnimation anim = new ColorAnimation();anim.Duration = new Duration(TimeSpan.FromSeconds(0.2));anim.To = color;Storyboard.SetTargetName(anim, objName);Storyboard.SetTargetProperty(anim, new PropertyPath("(Button.Background).(SolidColorBrush.Color)"));return anim;}ColorAnimation SetAnimcirkie(Color color){ColorAnimation anim = new ColorAnimation();anim.Duration = new Duration(TimeSpan.FromSeconds(0.2)); anim.To = color;Storyboard.SetTargetName(anim, "ColoCirkle");Storyboard.SetTargetProperty(anim,new PropertyPath(GradientStop.ColorProperty)); return anim;}private void Button_MouseEnter(object sender, MouseEventArgs e){Button btn = (Button)sender;Color background = ((SolidColorBrush)btn.BorderBrush).Color; storyboard = new Storyboard();storyboard.Children.Add(SetAnimButton(background,btn.Name)); storyboard.Children.Add(SetAnimcirkie(background));storyboard.Begin(this);}private void Button_MouseLeave(object sender, MouseEventArgs e){Button btn = (Button)sender; storyboard = new Storyboard();storyboard.Children.Add(SetAnimButton(Color.FromRgb(113, 110, 110),btn.Name)); storyboard.Children.Add(SetAnimcirkie(Color.FromArgb(150, 67,67,67)));storyboard.Begin(this);}private void gMenu_MouseDown(object sender, MouseButtonEventArgs e){DragMove();}}
}

WPF开发者QQ群: 340500857 

blogs: https://www.cnblogs.com/yanjinhua

Github:https://github.com/yanjinhuagood

出处:https://www.cnblogs.com/yanjinhua

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

转载请著名作者 出处 https://github.com/yanjinhuagood

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/302689.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MFC多语言实现方法

2019独角兽企业重金招聘Python工程师标准>>> 一、字符放在DLL资源文件中&#xff0c;切换资源模块(程序默认使用exe模块资源)。 实现要点&#xff1a; 新建一个只包含资源的DLL。通过函数AfxSetResourceHandle设置资源模块。 示意代码为&#xff1a; AfxSetResource…

oracle dbfile数,通过案例学调优之--Oracle参数(db_file_multiblock_read_count)

通过案例学调优之--Oracle参数(db_file_multiblock_read_count)应用环境&#xff1a;操作系统&#xff1a; RedHat EL55Oracle&#xff1a; Oracle 10gR2Oracle DB_FILE_MULTIBLOCK_READ_COUNT是Oracle比较重要的一个全局性参数&#xff0c;可以影响系统级别及sessioin级别。…

转行程序员后,我开始后悔没做这件事

全世界有3.14 % 的人已经关注了数据与算法之美程序 数据结构 算法 ——图灵奖得主&#xff0c;计算机科学家N.Wirth(沃斯)作为程序员&#xff0c;我们做机器学习也好&#xff0c;做python开发也好&#xff0c;java开发也好。有一种对所有程序员无一例外的刚需 —— 算法与数据…

Oracle应用集群详解

了解兼容性Oracle真正应用集群环境要运行与在同一群集数据库的不同版本的Oracle RAC的配置&#xff0c;还必须安装集群。例如&#xff0c;要运行在同一个集群Oracle9i和Oracle 10g&#xff1a;对于Oracle RAC节点上运行的Oracle9i数据库&#xff0c;您必须安装Oracle9i集群&…

工业互联网的两种极端想法和两点反思

目 录1. 概述2. 两种极端想法3. 两点反思1. 概述最近走访了很多企业&#xff0c;涉及到的行业包括&#xff1a;军工、特钢、有色、加工制造&#xff08;海洋钻井平台&#xff09;、建材、纺织等&#xff0c;在与不同的行业交流的过程中&#xff0c;我发现…

oracle重新编译package,如何有效的编译数据库中的失效对象(Package,trigger等)

在utlrp.sql脚本中&#xff0c;Oracle注释到&#xff1a;Rem utlrp.sql - UTiLity script Recompile invalid Pl/sql modulesRemRem DESCRIPTIONRem This is a fairly general script that can be used at any time toRem recompile all existing invalid PL/SQL modules in a …

兵马未至,数据先行,且看如何进行数据挖掘!

从数据中抽取信息从信息中挖掘知识随着大数据时代的到来&#xff0c;数据挖掘的重要性越发显著。可谓是兵马未至&#xff0c;数据先行。所谓数据挖掘&#xff0c;一般是指从大型数据库中将隐藏的预测信息抽取出来的过程&#xff0c;而更为精确的解释就是“从数据中挖掘知识”。…

微软加入字节码联盟,进一步开发支持Blazor 的WebAssembly技术

字节码联盟 (Bytecode Alliance)宣布已正式成为 501(c)(3) 非营利组织&#xff0c;参与组建的企业/组织包括 Fastly、英特尔、Mozilla 和微软&#xff0c;此外还邀请到了 Arm、DFINITY Foundation、Embark Studios、谷歌、Shopify 和加州大学圣地亚哥分校加入并成为正式会员。B…

印象笔记的试用印象

用过有道笔记&#xff0c;现在正在用麦库。总的来说&#xff0c;越来越依赖&#xff0c;感觉非常好用。现在已经超越我手机里的鲜果联播&#xff0c;成为第一常用的软件了。 不说麦库&#xff0c;最近听说evernote出了国内版&#xff0c;想起原来选择手机笔记软件时也比较过eve…

oracle外网监听端口,oracle 11g 修改默认监听端口1521

OS:Oracle Linux Server release 5.7DB:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production1、查看监听状态&#xff1a;SQL> !lsnrctl statusLSNRCTL for Linux: Version 11.2.0.3.0 - Production on 12-NOV-2013 01:36:29Copyright (c) 1991,…

传说中的贝叶斯统计到底有什么来头?

全世界有3.14 % 的人已经关注了数据与算法之美贝叶斯统计在机器学习中占有一个什么样的地位&#xff0c;它的原理以及实现过程又是如何的&#xff1f;本文对相关概念以及原理进行了介绍。引言&#xff1a;在很多分析学者看来&#xff0c;贝叶斯统计仍然是难以理解的。受机器学习…

更新两个WPF开源项目

前言好久没更新博客了&#xff0c;最近准备重拾博客&#xff0c;将更新恢复起来。开源项目这些年零零散散做了很多项目&#xff0c;准备整理一下&#xff0c;将其开源&#xff0c;现整理了两个项目&#xff1a;绑定引擎&#xff08;BindingEngine&#xff09;&#xff0c;插件式…

OpenGL ES 3D 粒子系统小结

2019独角兽企业重金招聘Python工程师标准>>> 所谓粒子系统可以想象为一堆粒子由一个点或一个面按照一定的规律进行喷射。 粒子系统大致分为2类&#xff1a;一类为“点喷式”&#xff0c;一类为“面喷式”。可以想象前者由一个点进行喷射&#xff0c;类似于焰火&…

理科生用创意毁灭世界,爆笑!

全世界有3.14 % 的人已经关注了数据与算法之美1、青年问禅师&#xff1a;“大师&#xff0c;我很爱我的女朋友&#xff0c;她也有很多优点&#xff0c;但是总有几个缺点让我非常讨厌&#xff0c;有什么方法能让她改变&#xff1f;”禅师浅笑&#xff0c;答&#xff1a;“方法很…

php 派生类 构造,C++派生类的构造函数和析构函数

派生类对象中包含基类对象&#xff0c;因此派生类对象在创建时&#xff0c;除了要调用自身的构造函数进行初始化外&#xff0c;还要调用基类的构造函数初始化其包含的基类对象。因此&#xff0c;程序中任何能够生成派生类对象的语句&#xff0c;都要说明其包含的基类对象是如何…

我的C#/.NET学习诀窍——LINQPad

在我以往的文章中&#xff0c;尤其涉及代码演示的&#xff0c;都使用了同一个工具——LINQPad。但许多客户面对我分享的.linq源文件都迷茫不知所措&#xff0c;因此有必要来聊聊一下这个强大的工具。本文首先将对该工具做个简单的介绍&#xff0c;并且分享一些LINQPad的优点&am…

数学在生活中无处不在,36个生活小故事涵盖小学所有的数学知识!

数学不是脱离生活的&#xff0c;而是源于生活&#xff0c;更要回归于生活。解决生活中遇到的问题&#xff0c;就是最自然的数学应用题。生活场景中的学习&#xff0c;是最生动的体验式学习机会。用学到的数学知识来解决生活中的问题&#xff0c;正是孩子体会数学奥妙的绝佳机会…

每天的0点php,使用strtotime,这个月的第一天凌晨0点在PHP?(Using just strtotime, 0 am first day of this month in PHP?)...

使用strtotime&#xff0c;这个月的第一天凌晨0点在PHP&#xff1f;(Using just strtotime, 0 am first day of this month in PHP?)echo mydate(strtotime(1 am first day of this month));以上工作结果2017-10-01 01:00:00 &#xff0c;但我很难在凌晨0点做到。 24am, 24pm,…

面试八股文:你写过自定义任务调度器吗?

最近入职了新公司&#xff0c;尝试阅读祖传代码&#xff0c;记录并更新最近的编程认知。思绪由Q1引发&#xff0c;后续Q2、Q3基于Q1的发散探究Q1. Task.Run、Task.Factory.StartNew 的区别&#xff1f;我们常使用Task.Run和Task.Factory.StartNew创建并启动任务&#xff0c;但是…

快速掌握MATLAB应用,从这一步开始

有人说&#xff0c;“MATLAB除了不会生孩子&#xff0c;什么都会。”矩阵运算、数据可视化、GUI&#xff08;用户界面&#xff09;设计、甚至是连接其他编程语言&#xff0c;MATLAB都能轻松实现&#xff01;那么&#xff0c;MATLAB到底有多厉害&#xff1f;MATLAB拥有丰富的算法…