WPF 实现任务栏角徽
生活随笔
收集整理的這篇文章主要介紹了
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 实现任务栏角徽的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .net中单元测试
- 下一篇: 听说过Netflix的Chaos Mon