WPF 实现任务栏角徽
WPF开发者QQ群: 340500857 | 微信群 -> 进入公众号主页 加入组织
欢迎转发、分享、点赞、在看,谢谢~。
01
—
效果预览
效果预览(更多效果请下载源码体验):
一、TaskbarItemInfoExample.xaml代码如下
<Window x:Class="WPFDevelopers.Samples.ExampleViews.TaskbarItemInfoExample"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WPFDevelopers.Samples"Owner="{x:Static local:App.CurrentMainWindow}"WindowStartupLocation="CenterOwner" Title="TaskbarItemInfoExample"mc:Ignorable="d" Height="211" Width="363"d:DesignHeight="450" d:DesignWidth="800"><Window.TaskbarItemInfo><TaskbarItemInfo /></Window.TaskbarItemInfo><Window.Resources><DataTemplate x:Key="TaskbarIcon"><Border Width="20" Height="20"Background="{StaticResource PrimaryPressedSolidColorBrush}"BorderBrush="{StaticResource WhiteSolidColorBrush}" BorderThickness="2"><TextBlock Text="{Binding}" TextAlignment="Center" Foreground="White" VerticalAlignment="Center"/></Border></DataTemplate></Window.Resources><WrapPanel VerticalAlignment="Center" HorizontalAlignment="Center"><Button Content="增加" Style="{StaticResource PrimaryButton}" Height="30" Width="120" Click="Button_Click" Tag="add"/><Button Content="移除" Style="{StaticResource PrimaryButton}" Height="30" Width="120" Click="Button_Click" Tag="remove"/></WrapPanel>
</Window>
二、TaskbarItemInfoExample.xaml.cs 代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace WPFDevelopers.Samples.ExampleViews
{/// <summary>/// TaskbarItemInfoExample.xaml 的交互逻辑/// </summary>public partial class TaskbarItemInfoExample : Window{int iconWidth = 20;int iconHeight = 20;RenderTargetBitmap renderTargetBitmap;ContentControl contentControl;public TaskbarItemInfoExample(){InitializeComponent();this.Loaded += (s, e) =>{renderTargetBitmap = new RenderTargetBitmap(iconWidth, iconHeight, 96, 96, PixelFormats.Default);contentControl = new ContentControl();contentControl.ContentTemplate = ((DataTemplate)Resources["TaskbarIcon"]);};}private void Button_Click(object sender, RoutedEventArgs e){var btn = sender as Button;switch (btn.Tag.ToString()){case "add":CurrentTaskbarItemInfo("99");break;case "remove":TaskbarItemInfo.Overlay = null;break;default:break;}}void CurrentTaskbarItemInfo(string value){contentControl.Content = value;contentControl.Arrange(new Rect(0, 0, iconWidth, iconHeight));renderTargetBitmap.Render(contentControl);TaskbarItemInfo.Overlay = (ImageSource)renderTargetBitmap;}}
}
源码地址
github:https://github.com/yanjinhuagood/WPFDevelopers.git
gitee:https://gitee.com/yanjinhua/WPFDevelopers.git
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
WPF 实现任务栏角徽相关推荐
- WPF中任务栏只显示主窗口
我们在用WPF开发的时候,常常会遇到在主窗口打开的情况下,去显示子窗口,而此时任务栏同时显示主窗口与子窗口.这样看起来很不美观.所以在弹出子窗口之前,设置它的几个相应属性,便不会出现这种问题了. 1 ...
- win11 任务栏角溢出里的程序图标记录如何删除(WIN 缓存图标清理)
rem 关闭Windows外壳程序explorer taskkill /f /im explorer.exe rem 清理系统图标缓存数据库 attrib -h -s -r "%userpr ...
- 看看这套WPF开源基础控件库:WPFDevelopers
此项目包含了 微信公众号 < WPF开发者> 日常开发分享,欢迎Star. 运行环境 Visual Studio 2019,dotNet Framework 4.0 SDK 欢迎关注微信公 ...
- 分享Silverlight/WPF/Windows Phone一周学习导读(07月25日-07月31日)
上周,微软发布Visual Studio LightSwitch 2011正式版,为商业应用开发人员推出一个新的应用开发产品.Visual Studio LightSwitch 2011 作为一种简单 ...
- WPF 4 日历控件(Calendar)
WPF 4 日历控件(Calendar) 原文:WPF 4 日历控件(Calendar) 在之前我已经写过两篇关于WPF 4 任务栏(Taskbar)相关的特性.相信自从VS2010 Beta 版放出 ...
- Win11任务栏图标重叠怎么办 Win11任务栏图标重叠的解决方法
Win11操作系统也推出一段时间了,不少小伙都有下载体验,但有一些小伙伴在使用Win11系统的时候发现自己任务栏图标重叠在一起,那么碰到这种情况应该怎么办,下面就和小编一起来看看有什么解决方法. Wi ...
- win11任务栏怎么显示软件图标
win11任务栏怎么显示软件图标 1.在任务栏的空白处,右键点击桌面空白处,选择[任务栏设置] 2.进入个性化后,在右侧的菜单中找到盘[任务栏角溢出] 3.点击任务栏角溢出后,将将要显示的应用图标开关 ...
- wpf 日期选择对话窗_WPF 4 日历控件(Calendar)
在之前我已经写过两篇关于WPF 4 任务栏(Taskbar)相关的特性.相信自从VS2010 Beta 版放出后,WPF 的粉丝们肯定在第一时间了解了WPF 4 的一些新控件及新功能.赶在明天Visu ...
- win11如何显示所有应用图标 Windows11显示所有应用图标的设置方法
现在很多用户都应该安装了Win11系统了吧,但是有许多用户针对Windows11的不显示所有图标有点难受,想设置不知道从哪里设置,显示所有图标的方法和Win10有所不同,下面小编就教大家显示所有图标的 ...
最新文章
- 凯文凯利:未来世界发展七大趋势
- 发现了一个很好的做excel、ppt 水晶易表、spss的好网站
- ssh: connect to host github.com port 22: Connection timed out
- uniapp增加百度统计代码(h5)
- 【防守方基础】危险报文识别
- 使用useEffect常见问题!
- Linux 命令(110)—— help 命令(builtin)
- LeetCode 220_Contains Duplicate III
- python部署到服务器上解析不到模块_在服务器上部署kafka-python包
- 地籍图宗记注记标注实现
- java商城源码(servlet,springboot,html,vue,uniapp,小程序,android)一套任意组合
- (原)使用ass字幕文件通过ffmpeg给视频添加字幕的一些研究
- SQL SERVER 实用教程(第四版) 实验 1-10 非标准答案
- yapi文档转换jmx脚本
- c语言比较函数memcmp,c语言函数memcmp()如何比较内存前n个字节实例源码介绍
- 【C# 】泛型,减少代码的方式
- 四棱锥和三棱锥重叠求面数
- chrome插件莫名消失【已解决】
- 蓝桥杯51单片机学习——proteus8关于51工程文件的创建
- android动态交换控件位置,Android DynamicGrid实现拖曳交换位置功能
热门文章
- ExtJs 带分页的comboBox
- WSUS服务器的建立以及客户端发布
- AS3.0第一个实例:(Hello World)
- Linux主机名那点事儿
- php mysql insert 变量,php – 在blueimp / jquery-file-upload上添加更多自定义变量给mysql insert...
- 【CH4302】Interval GCD
- 2-1 gradle安装
- iOS - 上架的APP 生成二维码下载
- hibernate -- hello world
- ExtJs5.0在WebStorm上的使用之入门教程(一)编写第一个网页 HelloExt