翼度科技»论坛 编程开发 .net 查看内容

4.WPF样式使用规范

7

主题

7

帖子

21

积分

新手上路

Rank: 1

积分
21
在Web开发的时候,编写css样式的时候通常是统一写在.css样式文件中。在WPF中也可以使用这样的思想。
样式引用:
1.新建一个项目用于统一存放样式WPF.UI
添加一个资源字典Button.xaml或者CheckBox.xaml等等....
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  5.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  8. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  9.    
  10.    
  11. </ResourceDictionary>
复制代码
 
2.添加Generic.xaml用于统一管理所有文件
ResourceDictionary.MergedDictionaries是一个属性,它允许您将多个ResourceDictionary合并到一个ResourceDictionary中。这使得在应用程序中共享资源变得更加方便。
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  5.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  8. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  9.    
  10.    
  11. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  12. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  13.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  14.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  15.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  16.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  17.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  18. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  19.    
  20.    
  21. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  22. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  23.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  24.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  25.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  26.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  27.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  28. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  29.    
  30.    
  31. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  32. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  33.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  34.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  35.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  36.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  37.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  38. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  39.    
  40.    
  41. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  42. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  43.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  44.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  45.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  46.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  47.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  48. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  49.    
  50.    
  51. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  52. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  53.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  54.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  55.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  56.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  57.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  58. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  59.    
  60.    
  61. </ResourceDictionary>
复制代码
 
3.在主项目中App.xaml添加引用
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  5.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  8. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  9.    
  10.    
  11. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  12. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  13.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  14.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  15.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  16.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  17.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  18. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  19.    
  20.    
  21. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  22. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  23.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  24.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  25.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  26.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  27.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  28. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  29.    
  30.    
  31. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  32. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  33.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  34.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  35.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  36.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  37.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  38. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  39.    
  40.    
  41. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  42. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  43.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  44.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  45.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  46.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  47.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  48. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  49.    
  50.    
  51. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  52. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  53.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  54.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  55.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  56.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  57.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  58. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  59.    
  60.    
  61. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  62. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  63.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  64.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  65.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  66.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  67.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  68. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  69.    
  70.    
  71. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  72. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  73.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  74.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  75.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  76.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  77.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  78. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  79.    
  80.    
  81. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  82. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  83.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  84.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  85.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  86.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  87.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  88. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  89.    
  90.    
  91. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  92. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  93.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  94.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  95.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  96.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  97.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  98. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  99.    
  100.    
  101. </ResourceDictionary>
复制代码
 
4.使用
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  5.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  8. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  9.    
  10.    
  11. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  12. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  13.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  14.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  15.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  16.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  17.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  18. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  19.    
  20.    
  21. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  22. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  23.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  24.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  25.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  26.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  27.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  28. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  29.    
  30.    
  31. </ResourceDictionary>   
复制代码
 
图标引用:
1.创建一个文件夹用于存放图片,图片属性设置为资源

 2.添加一个资源文件Icon.xaml
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  5.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  8. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  9.    
  10.    
  11. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  12. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  13.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  14.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  15.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  16.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  17.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  18. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  19.    
  20.    
  21. </ResourceDictionary>
复制代码
BitmapImage 表示可以在WPF应用程序中使用的图像源。它用于在各种WPF控件中显示图像,如Image、ImageBrush和MediaElement。BitmapImage可以从各种来源创建,例如文件路径、流或URI。它提供了在WPF应用程序中加载、解码和操作图像的属性和方法。
3.在Generic.xaml文件里添加引用,如上。
  1. [/code]4.添加一个转化器
  2. [code]///     /// 根据ICON的字符串名称转换为BitmapImage对象    ///     internal class[b] IconToImageConverter[/b] : IValueConverter    {<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  5.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  8.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  9. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  10.    
  11.    
  12. </ResourceDictionary>public object Convert(object value, Type targetType, object parameter, CultureInfo culture)<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  13. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  14.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  15.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  16.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  17.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  18.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  19. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  20.    
  21.    
  22. </ResourceDictionary>{<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  23. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  24.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  25.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  26.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  27.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  28.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  29. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  30.    
  31.    
  32. </ResourceDictionary>    return (BitmapImage)System.Windows.Application.Current.Resources[(string)value];<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  33. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  34.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  35.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  36.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  37.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  38.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  39. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  40.    
  41.    
  42. </ResourceDictionary>}<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  43. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  44.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  45.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  46.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  47.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  48.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  49. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  50.    
  51.    
  52. </ResourceDictionary>public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  53. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  54.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  55.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  56.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  57.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  58.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  59. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  60.    
  61.    
  62. </ResourceDictionary>{<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  63. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  64.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  65.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  66.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  67.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  68.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  69. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  70.    
  71.    
  72. </ResourceDictionary>    throw new NotImplementedException();<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  73. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  74.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  75.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  76.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  77.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  78.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  79. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  80.    
  81.    
  82. </ResourceDictionary>}    }
复制代码
5使用
  1. //.cs代码 public override string [b]Icon[/b] => "[b]Icon_Test[/b]";//.xaml代码<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  5.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  6.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  7.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  8. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  9.    
  10.    
  11. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  12. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  13.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  14.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  15.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  16.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  17.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  18. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  19.    
  20.    
  21. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  22. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  23.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  24.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  25.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  26.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  27.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  28. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  29.    
  30.    
  31. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  32. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  33.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  34.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  35.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  36.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  37.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  38. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  39.    
  40.    
  41. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  42. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  43.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  44.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  45.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  46.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  47.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  48. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  49.    
  50.    
  51. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  52. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  53.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  54.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  55.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  56.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  57.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  58. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  59.    
  60.    
  61. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  62. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  63.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  64.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  65.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  66.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  67.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  68. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  69.    
  70.    
  71. </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  72. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  73.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  74.     <BitmapImage x:Key="<strong>Icon_Test</strong>" UriSource="/WPF.UI;Component/Icon/010_出差申请.png"/>
  75.     <BitmapImage x:Key="<strong>Icon_Sobel</strong>" UriSource="/WPF.UI;Component/Icon/010_打卡签到.png"/>
  76.     <BitmapImage x:Key="<strong>Icon_MedianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_发现更多.png"/>
  77.     <BitmapImage x:Key="<strong>Icon_GaussianBlur</strong>" UriSource="/WPF.UI;Component/Icon/010_费用报销.png"/>
  78. </ResourceDictionary>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  79.    
  80.    
  81. </ResourceDictionary>      
复制代码
 

来源:https://www.cnblogs.com/MingQiu/p/18007533
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具