最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于WPF實(shí)現(xiàn)路徑圖標(biāo)控件

 更新時(shí)間:2023年07月28日 09:09:17   作者:WPF開發(fā)者  
這篇文章主要介紹了如何利用WPF實(shí)現(xiàn)路徑圖標(biāo)控件,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)或工作有一定幫助,需要的小伙伴可以參考一下

WPF 實(shí)現(xiàn)路徑圖標(biāo)控件

框架使用.NET4;

Visual Studio 2022;

實(shí)現(xiàn)方法

1)新增 PathIcon.cs 代碼如下:

定義PathIcon類,它繼承自Control類,新增兩個(gè)依賴屬性

  • Kind屬性是一個(gè)枚舉類型的依賴屬性,用于指定圖標(biāo)的種類。
  • Data屬性是一個(gè)Geometry類型的依賴屬性,用于存儲圖標(biāo)的路徑數(shù)據(jù)。

OnKindChanged當(dāng)Kind屬性發(fā)生變化時(shí)會被調(diào)用。它首先獲取新值,并根據(jù)新值構(gòu)建資源名稱。然后,通過調(diào)用FindResource方法查找對應(yīng)的$"WD.{kind}Geometry"資源,并將其賦值給Data屬性。

using?System.Windows;
using?System.Windows.Controls;
using?System.Windows.Media;
namespace?WPFDevelopers.Controls
{
????public?class?PathIcon?:?Control
????{
????????public?static?readonly?DependencyProperty?KindProperty?=
????????????DependencyProperty.Register(nameof(Kind),?typeof(string),?typeof(PathIcon),
????????????????new?PropertyMetadata(string.Empty,?OnKindChanged));
????????public?static?readonly?DependencyProperty?DataProperty?=
????????????DependencyProperty.Register(nameof(Data),?typeof(Geometry),?typeof(PathIcon));
????????public?PackIconKind?Kind
????????{
????????????get?{?return?(PackIconKind)GetValue(KindProperty);?}
????????????set?{?SetValue(KindProperty,?value);?}
????????}
????????public?Geometry?Data
????????{
????????????get?{?return?(Geometry)GetValue(DataProperty);?}
????????????set?{?SetValue(DataProperty,?value);?}
????????}
????????private?static?void?OnKindChanged(DependencyObject?d,?DependencyPropertyChangedEventArgs?e)
????????{
????????????var?pathIcon?=?(PathIcon)d;
????????????var?kind?=?(string)e.NewValue;
????????????if?(!string.IsNullOrWhiteSpace(kind))
????????????{
????????????????kind?=?$"WD.{kind}Geometry";
????????????????pathIcon.Data?=?(Geometry)pathIcon.FindResource(kind);
????????????}
????????????else
????????????????pathIcon.Data?=?null;
????????}
????????static?PathIcon()
????????{
????????????DefaultStyleKeyProperty.OverrideMetadata(typeof(PathIcon),?new?FrameworkPropertyMetadata(typeof(PathIcon)));
????????}
????}
}

2)新增 PathIcon.xaml 代碼如下:

使用Viewbox控件包裹Path控件,以實(shí)現(xiàn)路徑圖標(biāo)的縮放效果。

<ResourceDictionary
????xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
????xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
????xmlns:controls="clr-namespace:WPFDevelopers.Controls">
????<ResourceDictionary.MergedDictionaries>
????????<ResourceDictionary?Source="Basic/ControlBasic.xaml"?/>
????</ResourceDictionary.MergedDictionaries>
????<Style
????????x:Key="WD.PathIcon"
????????BasedOn="{StaticResource?WD.ControlBasicStyle}"
????????TargetType="{x:Type?controls:PathIcon}">
????????<Setter?Property="Padding"?Value="0"?/>
????????<Setter?Property="FocusVisualStyle"?Value="{x:Null}"?/>
????????<Setter?Property="Focusable"?Value="False"?/>
????????<Setter?Property="Height"?Value="16"?/>
????????<Setter?Property="VerticalAlignment"?Value="Center"?/>
????????<Setter?Property="VerticalContentAlignment"?Value="Stretch"?/>
????????<Setter?Property="Foreground">
????????????<Setter.Value>
????????????????<Binding?Path="Foreground"?RelativeSource="{RelativeSource?Mode=FindAncestor,?AncestorType={x:Type?Control}}"?/>
????????????</Setter.Value>
????????</Setter>
????????<Setter?Property="Width"?Value="16"?/>
????????<Setter?Property="Template">
????????????<Setter.Value>
????????????????<ControlTemplate?TargetType="{x:Type?controls:PathIcon}">
????????????????????<Viewbox
????????????????????????Margin="{TemplateBinding?Padding}"
????????????????????????HorizontalAlignment="{TemplateBinding?HorizontalContentAlignment}"
????????????????????????VerticalAlignment="{TemplateBinding?VerticalContentAlignment}"
????????????????????????UseLayoutRounding="True">
????????????????????????<Path
????????????????????????????x:Name="PART_Path"
????????????????????????????Data="{TemplateBinding?Data}"
????????????????????????????Fill="{TemplateBinding?Foreground}"
????????????????????????????SnapsToDevicePixels="{TemplateBinding?SnapsToDevicePixels}"
????????????????????????????Stretch="Uniform"
????????????????????????????UseLayoutRounding="False"?/>
????????????????????</Viewbox>
????????????????</ControlTemplate>
????????????</Setter.Value>
????????</Setter>
????</Style>
????<Style
????????x:Key="WD.MiniPathIcon"
????????BasedOn="{StaticResource?WD.PathIcon}"
????????TargetType="{x:Type?controls:PathIcon}">
????????<Setter?Property="Height"?Value="10"?/>
????????<Setter?Property="Width"?Value="7"?/>
????</Style>
????<Style?BasedOn="{StaticResource?WD.PathIcon}"?TargetType="{x:Type?controls:PathIcon}"?/>
</ResourceDictionary>

3)新增示例 PathIconExample.xaml 代碼如下:

<UniformGrid
????????????HorizontalAlignment="Center"
????????????VerticalAlignment="Center"
????????????Columns="6"
????????????Rows="2">
????????????<Button
????????????????Margin="4"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.PrimaryButton}">
????????????????<wd:PathIcon?Data="M682?256h256v256l-98-98-268?268-170-170-256?256-60-60?316-316?170?170?208-208z"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.DangerPrimaryButton}">
????????????????<wd:PathIcon?Kind="Arrow"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.DangerDefaultButton}">
????????????????<wd:PathIcon?Kind="SortArrow"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.WarningDefaultButton}">
????????????????<wd:PathIcon?Kind="SmileyOutline"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.DefaultButton}">
????????????????<wd:PathIcon?Kind="Replace"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:Badge.HorizontalOffset="17"
????????????????wd:Badge.IsShow="True"
????????????????wd:Badge.VerticalOffset="8"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.SuccessDefaultButton}">
????????????????<wd:PathIcon?Kind="Home"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:ElementHelper.IsRound="True"
????????????????Style="{StaticResource?WD.NormalButton}">
????????????????<wd:PathIcon?PathData="M682?256h256v256l-98-98-268?268-170-170-256?256-60-60?316-316?170?170?208-208z"?/>
????????????</Button>
????????????<Button?Margin="4"?Style="{StaticResource?WD.SuccessPrimaryButton}">
????????????????<wd:PathIcon?Kind="Arrow"?/>
????????????</Button>
????????????<Button?Margin="4"?Style="{StaticResource?WD.DangerPrimaryButton}">
????????????????<wd:PathIcon?Kind="SortArrow"?/>
????????????</Button>
????????????<Button
????????????????Margin="4"
????????????????wd:Badge.IsShow="True"
????????????????Style="{StaticResource?WD.WarningPrimaryButton}">
????????????????<wd:PathIcon
????????????????????Width="20"
????????????????????Height="20"
????????????????????Kind="SmileyOutline"?/>
????????????</Button>
????????????<Button?Margin="4"?Style="{StaticResource?WD.PrimaryButton}">
????????????????<wd:PathIcon?Kind="Replace"?/>
????????????</Button>
????????????<Button?Margin="4"?Style="{StaticResource?WD.SuccessPrimaryButton}">
????????????????<StackPanel?Orientation="Horizontal">
????????????????????<wd:PathIcon?Kind="Home"?/>
????????????????????<TextBlock?Margin="4,0"?Text="Home"?/>
????????????????</StackPanel>
????????????</Button>
????????</UniformGrid>

效果圖

到此這篇關(guān)于基于WPF實(shí)現(xiàn)路徑圖標(biāo)控件的文章就介紹到這了,更多相關(guān)WPF路徑圖標(biāo)控件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C# 多態(tài)性的深入理解

    C# 多態(tài)性的深入理解

    本篇文章是對C#中的多態(tài)性進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • C#中的兩種debug方法介紹

    C#中的兩種debug方法介紹

    這篇文章主要介紹了C#中的兩種debug方法介紹,本文講解了代碼用 #if DEBUG 包裹、利用宏定義兩種方法,需要的朋友可以參考下
    2015-02-02
  • C#中字符串優(yōu)化String.Intern、IsInterned詳解

    C#中字符串優(yōu)化String.Intern、IsInterned詳解

    這篇文章主要給大家介紹了關(guān)于C#中字符串優(yōu)化String.Intern、IsInterned的相關(guān)資料,文中通過示例代碼介紹的,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-12-12
  • C#實(shí)現(xiàn)Modbus通信功能的示例詳解

    C#實(shí)現(xiàn)Modbus通信功能的示例詳解

    Modbus作為一種開放且廣泛采用的通信協(xié)議,在實(shí)現(xiàn)設(shè)備間數(shù)據(jù)交換方面發(fā)揮著至關(guān)重要的作用,它不僅支持多種物理層接口(如RS-232,?RS-485,?以及以太網(wǎng)),還因其簡單易用的特點(diǎn)而被大家所青睞,本文通過實(shí)際示例介紹如何在C#項(xiàng)目中輕松實(shí)現(xiàn)Modbus通信功能
    2024-11-11
  • C#垃圾回收機(jī)制的詳細(xì)介紹

    C#垃圾回收機(jī)制的詳細(xì)介紹

    這篇文章詳細(xì)介紹了C#垃圾回收機(jī)制,有需要的朋友可以參考一下
    2013-09-09
  • WPF使用Accord實(shí)現(xiàn)屏幕錄制功能

    WPF使用Accord實(shí)現(xiàn)屏幕錄制功能

    這篇文章主要為大家詳細(xì)介紹了WPF如何使用Accord實(shí)現(xiàn)屏幕錄制,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下
    2024-03-03
  • C# wx獲取token的基本方法

    C# wx獲取token的基本方法

    這篇文章主要為大家詳細(xì)介紹了C# wx獲取token的基本方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 使用C#實(shí)現(xiàn)對任意區(qū)域任意大小的截圖

    使用C#實(shí)現(xiàn)對任意區(qū)域任意大小的截圖

    這篇文章主要為大家詳細(xì)介紹了如何使用C#實(shí)現(xiàn)簡單的截圖功能,可以對任意區(qū)域任意大小的截圖,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • C#連接SQLite數(shù)據(jù)庫并實(shí)現(xiàn)基本操作

    C#連接SQLite數(shù)據(jù)庫并實(shí)現(xiàn)基本操作

    本文介紹了SQLite,一個(gè)輕量級的跨平臺數(shù)據(jù)庫管理系統(tǒng),以及如何在C#中使用System.Data.SQLite庫進(jìn)行操作,包括創(chuàng)建、修改和查詢數(shù)據(jù)庫,以及使用SQLiteHelper類簡化SQL使用,此外,還提到了DB文件查看工具SQLiteSpy的應(yīng)用,需要的朋友可以參考下
    2024-12-12
  • C#過濾sql特殊字符串的方法

    C#過濾sql特殊字符串的方法

    這篇文章介紹了C#過濾sql特殊字符串的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07

最新評論

建始县| 昭觉县| 新津县| 永年县| 鹤岗市| 准格尔旗| 石台县| 绥芬河市| 保山市| 新龙县| 青州市| 确山县| 新丰县| 拉萨市| 峨山| 和硕县| 西宁市| 吐鲁番市| 甘孜| 盐池县| 宜川县| 剑河县| 寻乌县| 康马县| 七台河市| 伊吾县| 色达县| 郓城县| 锡林浩特市| 怀来县| 宜春市| 弥渡县| 尉氏县| 辽阳市| 栖霞市| 马尔康县| 鄂托克前旗| 宝清县| 莱西市| 博白县| 凌源市|