IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> 【WPF】使用SVG资源 -> 正文阅读

[开发工具]【WPF】使用SVG资源

1. SVG图标资源下载。

阿里图库

2. SVG转XAML

SvgToXaml

使用方式

  • 单个SVG图像转换成XAML
    运行SvgToXaml.exe,显示如下界面:
    在这里插入图片描述
    点击...按钮,选择SVG文件所在的文件夹。选择后,显示当前文件夹下所有可用图像。如下图所示:
    在这里插入图片描述
    双击需要转换的SVG图像,弹出以下界面:
    在这里插入图片描述
    选择Xaml选项卡,将显示转换后的XAML代码。如下所示:
    在这里插入图片描述
  • 多张SVG图像转换成XAML
    选择文件路径的于上一节中的步骤相同。
    在这里插入图片描述
    点击右上角红色框标注的按钮。将当前文件夹下的所有SVG图像转换到一个XAML文件中。
    在这里插入图片描述
    点击保存后,弹出以下对话框:
    在这里插入图片描述
    选择后,弹出以下对话框:
    在这里插入图片描述
    点击确定按钮后,弹出以下对话框:
    在这里插入图片描述
    点击是按钮,将生成一个bat文件和一个.tt文件。.tt文件加载到VS后,能够自动生成代码。如下所示:
    在这里插入图片描述
    但是,生成的C#代码比较多。也不一定是我们需要的。如下所示: 在这里插入图片描述
    一般情况下,都是只使用生成的XAML文件,后台的CS文件等手动配置。

3. 创建资源程序集

3.1 创建一个C#类库程序集

  • 删除自动生成的Class1.cs文件
  • 添加一个Themes文件夹
  • Themes文件夹下,新建一个Generic.xaml文件
  • 添加一个Images文件夹,以便存放图像相关的资源
  • Images文件夹下新建一个资源字典文件(例如,命名为IconDictionary.xaml)和一个.CS文件(例如命名为XXXResources.cs)
  • 打开AssemblyInfo.cs文件,在文件结尾处添加以下代码,并修正名称空间错误
    [assembly:ThemeInfo(ResourceDictionaryLocation.None,  ResourceDictionaryLocation.SourceAssembly)]
    

3.2 修改XXXResources.cs文件

在该文件中添加,一些需要使用到的资源索引键,如下所示:

using System.Windows;
namespace XXX.IconPacks.Images
{
    public static class XXXResources
    {
        public static ResourceKey ImageCalibrationKey 	=> MakeKey(nameof(ImageCalibrationKey));
        public static ResourceKey ImageCameraKey 		=> MakeKey(nameof(ImageCameraKey));
        public static ResourceKey ImageCommunicationKey => MakeKey(nameof(ImageCommunicationKey));
        public static ResourceKey ImageCompileKey 		=> MakeKey(nameof(ImageCompileKey));
        public static ResourceKey ImageDeleteKey 		=> MakeKey(nameof(ImageDeleteKey));
        public static ResourceKey ImageDescriptionKey 	=> MakeKey(nameof(ImageDescriptionKey));
        public static ResourceKey ImageEditorKey 		=> MakeKey(nameof(ImageEditorKey));
        public static ResourceKey ImageExportKey 		=> MakeKey(nameof(ImageExportKey));
        public static ResourceKey ImageImportKey 		=> MakeKey(nameof(ImageImportKey));
        public static ResourceKey ImageMoveDownKey 		=> MakeKey(nameof(ImageMoveDownKey));
        public static ResourceKey ImageMoveUpKey	 	=> MakeKey(nameof(ImageMoveUpKey));
        public static ResourceKey ImageNewKey 			=> MakeKey(nameof(ImageNewKey));
        public static ResourceKey ImageRenameKey 		=> MakeKey(nameof(ImageRenameKey));
        public static ResourceKey ImageResetKey 		=> MakeKey(nameof(ImageResetKey));
        public static ResourceKey ImageRunKey 			=> MakeKey(nameof(ImageRunKey));
        public static ResourceKey ImageToolSetKey 		=> MakeKey(nameof(ImageToolSetKey));
        private static ComponentResourceKey MakeKey(object id)
        {
            return new ComponentResourceKey(typeof(XXXResources), id);
        }
    }
}

3.3 修正IconDictionary.xaml文件

SvgToXaml.exe工具生成的xaml文件拷贝到该文件中,并修改每个DrawingImage对象的Key为XXXResources.cs文件中对应的键。如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:images="clr-namespace:XXX.IconPacks.Images">
    <DrawingImage x:Key="{x:Static images:XXXResources.ImageCalibrationKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M374.977267,331.748706C374.977267,347.996762,361.80473,361.168759,345.556008,361.168759L227.871998,361.16876C211.623276,361.16876,198.450739,347.996763,198.450739,331.748707L198.450739,214.069517C198.450739,197.821461,211.623276,184.649464,227.871998,184.649464L345.556009,184.649464C361.804731,184.649464,374.977268,197.821461,374.977268,214.069517L374.977267,331.748706z M600.262241,214.069517C600.262241,197.821461,587.089704,184.649464,570.840982,184.649464L453.156971,184.649464C436.908249,184.649464,423.735712,197.821461,423.735712,214.069517L423.735712,331.748707C423.735712,347.996763,436.908249,361.16876,453.156971,361.16876L570.840982,361.16876C587.089704,361.16876,600.262241,347.996763,600.262241,331.748707L600.262241,214.069517z M824.365247,214.069517C824.365247,197.821461,811.191687,184.649464,794.943988,184.649464L677.258953,184.649464C661.010231,184.649464,647.837694,197.821461,647.837694,214.069517L647.837694,331.748707C647.837694,347.996763,661.010231,361.16876,677.258953,361.16876L794.943988,361.16876C811.191686,361.16876,824.365247,347.996763,824.365247,331.748707L824.365247,214.069517z M375.568763,436.627359C375.568763,420.379303,362.396226,407.207306,346.147504,407.207306L228.463493,407.207305C212.214771,407.207305,199.042234,420.379302,199.042234,436.627358L199.042234,554.307571C199.042234,570.555627,212.214771,583.727624,228.463493,583.727624L346.147504,583.727625C362.396226,583.727625,375.568763,570.555628,375.568763,554.307572L375.568763,436.627359z M600.85476,436.627359C600.85476,420.379303,587.682223,407.207306,571.433501,407.207306L453.748466,407.207305C437.499744,407.207305,424.327207,420.379302,424.327207,436.627358L424.327207,554.307571C424.327207,570.555627,437.499744,583.727624,453.748466,583.727624L571.432477,583.727624C587.681199,583.727624,600.853736,570.555627,600.853736,554.307571L600.853736,436.627359z M375.568763,662.256142C375.568763,646.007063,362.396226,632.836089,346.147504,632.836089L228.463493,632.836089C212.214771,632.836089,199.042234,646.007063,199.042234,662.256142L199.042234,779.935332C199.042234,796.183388,212.214771,809.355385,228.463493,809.355385L346.147504,809.355385C362.396226,809.355385,375.568763,796.183388,375.568763,779.935332L375.568763,662.256142z M600.85476,662.256142C600.85476,646.007063,587.682223,632.836089,571.433501,632.836089L453.748466,632.836089C437.499744,632.836089,424.327207,646.007063,424.327207,662.256142L424.327207,779.935332C424.327207,796.183388,437.499744,809.355385,453.748466,809.355385L571.432477,809.355385C587.681199,809.355385,600.853736,796.183388,600.853736,779.935332L600.853736,662.256142z M824.956743,662.256142C824.956743,646.007063,811.783183,632.836089,795.535484,632.836089L677.850449,632.836089C661.601727,632.836089,648.42919,646.007063,648.42919,662.256142L648.42919,779.935332C648.42919,796.183388,661.601727,809.355385,677.850449,809.355385L795.535484,809.355385C811.783182,809.355385,824.956743,796.183388,824.956743,779.935332L824.956743,662.256142z M824.956743,436.627359C824.956743,420.379303,811.783183,407.207306,795.535484,407.207306L677.850449,407.207306C661.601727,407.207306,648.42919,420.379303,648.42919,436.627359L648.42919,554.307572C648.42919,570.555628,661.601727,583.727625,677.850449,583.727625L795.535484,583.727625C811.783182,583.727625,824.956743,570.555628,824.956743,554.307572L824.956743,436.627359z M786.428709,545.44267L688.003086,545.44267 688.003086,447.02108 786.428709,447.02108 786.428709,545.44267z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageCameraKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M860.096,288.18L761.297,288.18C751.852,288.18,743.277,282.836,739.052,274.385L707.112,210.135C694.437,184.658,668.836,168.751,640.377,168.751L383.623,168.751C355.164,168.751,329.563,184.534,316.887,210.011L284.824,274.261C280.599,282.711,272.024,288.055,262.579,288.055L163.904,288.055C122.769,288.055,89.338,321.485,89.338,362.621L89.338,780.56C89.338,821.695,122.768,855.125,163.904,855.125L859.972,855.125C901.107,855.125,934.537,821.695,934.537,780.56L934.537,362.745C934.662,321.61,901.107,288.18,860.097,288.18z M884.951,780.56C884.951,794.23,873.766,805.415,860.096,805.415L163.904,805.415C150.234,805.415,139.049,794.23,139.049,780.56L139.049,362.745C139.049,349.075,150.234,337.89,163.904,337.89L262.579,337.89C291.038,337.89,316.639,322.107,329.315,296.63L361.378,232.38C365.603,223.929,374.178,218.585,383.623,218.585L640.253,218.585C649.697,218.585,658.273,223.805,662.498,232.38L694.437,296.506C707.113,321.982,732.714,337.89,761.173,337.89L859.972,337.89C873.642,337.89,884.827,349.075,884.827,362.745L884.827,780.56z" />
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M797.834,372.438C780.933,372.438 767.138,386.108 767.138,403.01 767.138,419.912 780.933,433.706 797.834,433.706 814.735,433.706 828.53,420.036 828.53,403.01 828.406,386.109 814.736,372.438 797.834,372.438z M512.373,353.673C403.01,353.673 314.029,442.654 314.029,552.017 314.029,661.38 403.01,750.36 512.373,750.36 621.736,750.36 710.717,661.378 710.717,552.016 710.717,442.654 621.735,353.672 512.373,353.672z M512.373,700.526C430.475,700.526 363.739,633.914 363.739,551.892 363.739,469.995 430.351,403.259 512.373,403.259 594.395,403.259 661.007,469.871 661.007,551.892 660.882,633.914 594.27,700.526 512.373,700.526z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>


    <DrawingImage x:Key="{x:Static images:XXXResources.ImageCommunicationKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M511.836371,205.525773A143.505155,143.505155,0,0,0,495.341526,491.876289L495.341526,1007.505155A16.494845,16.494845,0,0,0,511.836371,1024A16.494845,16.494845,0,0,0,528.331216,1007.505155L528.331216,491.876289A143.505155,143.505155,0,0,0,511.836371,205.525773z M511.836371,460.536082A111.175258,111.175258,0,1,1,623.011629,349.360825A111.175258,111.175258,0,0,1,511.836371,461.85567z M705.485856,118.43299A16.164948,16.164948,0,0,0,705.485856,141.525773A284.041237,284.041237,0,0,1,720.331216,542.350515A16.494845,16.494845,0,0,0,744.743588,564.783505A317.690722,317.690722,0,0,0,728.248742,117.443299A16.824742,16.824742,0,0,0,705.485856,118.43299z M295.094103,117.443299A317.690722,317.690722,0,0,0,274.970392,560.824742A16.494845,16.494845,0,0,0,287.176577,566.103093A17.814433,17.814433,0,0,0,298.393072,560.824742A16.824742,16.824742,0,0,0,298.393072,537.402062A284.701031,284.701031,0,0,1,316.207505,141.525773A16.164948,16.164948,0,0,0,316.207505,118.43299A16.824742,16.824742,0,0,0,295.094103,117.443299z M856.578639,4.948454A16.494845,16.494845,0,0,0,833.155959,4.948454A16.494845,16.494845,0,0,0,833.155959,28.041237A453.938144,453.938144,0,0,1,848.661113,654.845361A16.494845,16.494845,0,0,0,848.661113,678.268041A18.14433,18.14433,0,0,0,859.877608,682.556701A16.494845,16.494845,0,0,0,872.083794,676.948454A486.927835,486.927835,0,0,0,856.578639,4.948454z M163.795134,8.57732A487.257732,487.257732,0,0,0,147.960082,673.649485A16.824742,16.824742,0,0,0,160.166268,679.257732A18.14433,18.14433,0,0,0,171.382763,674.969072A16.824742,16.824742,0,0,0,171.382763,651.546392A453.938144,453.938144,0,0,1,187.217814,32.989691A16.494845,16.494845,0,0,0,187.217814,9.56701A16.164948,16.164948,0,0,0,163.795134,8.57732z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageCompileKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M70.213818,255.232L507.554909,0.139636 944.872727,255.232 944.872727,767.069091 507.554909,1022.138182 70.213818,765.44 70.213818,255.232z M871.982545,729.018182L871.982545,291.677091 507.531636,73.029818 143.080727,291.677091 143.080727,729.018182 507.531636,947.688727 871.982545,729.018182z M548.724364,549.957818L548.724364,795.554909C548.724364,813.009454 534.481455,827.252364 517.050182,827.252364 499.618909,827.252364 485.352727,814.568728 485.352727,795.554909L485.352727,548.398545 260.352,421.608727C246.085818,413.696 241.338182,393.099636 249.274182,377.250909 254.021818,370.920727 260.352,364.567273 268.288,362.984727 276.200727,361.402182 284.113455,361.402182 293.632,366.149818L517.050182,494.498909 737.303273,367.732364C751.569455,359.819637 772.165818,362.984728 780.078545,377.250909 787.991272,391.517091 783.243636,412.113454 769.000727,420.026182L548.747636,549.957818z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageDeleteKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M512,620.544L765.3376,873.8816A76.6976,76.6976,0,1,0,873.8816,765.3376L620.6464,512 873.8816,258.6624A76.6976,76.6976,0,1,0,765.3376,150.1184L512,403.3536 258.6624,150.1184A76.6976,76.6976,0,1,0,150.1184,258.6624L403.3536,512 150.1184,765.3376A76.6976,76.6976,0,1,0,258.6624,873.8816L512,620.6464z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageDescriptionKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M494.4,932.8L489.6,928 404.8,816 200,816C126.4,816,67.2,755.2,67.2,680L67.2,217.6C67.2,142.4,126.4,81.6,200,81.6L824,81.6C897.6,81.6,956.8,142.4,956.8,217.6L956.8,680C956.8,755.2,897.6,816,824,816L632,816 536,931.2C531.2,937.6 523.2,940.8 515.2,940.8 507.2,942.4 499.2,939.2 494.4,932.8z M518.4,867.2L598.4,771.2C604.8,764.8,612.8,760,622.4,761.6L824,761.6C865.6,761.6,900.8,724.8,900.8,681.6L900.8,217.6C900.8,172.8,865.6,137.6,824,137.6L200,137.6C158.4,137.6,123.2,174.4,123.2,217.6L123.2,680C123.2,724.8,158.4,760,200,760L424,760C433.6,760,443.2,764.8,448,774.4L518.4,867.2z M244.8,289.6C244.8,273.6,257.6,259.2,273.6,259.2L748.8,259.2C764.8,259.2 777.6,272 777.6,289.6 777.6,305.6 764.8,320 748.8,320L273.6,320C265.6,320 257.6,316.8 252.8,312 248,305.6 244.8,297.6 244.8,289.6z M244.8,438.4C244.8,422.4,257.6,408,273.6,408L748.8,408C764.8,408 777.6,420.8 777.6,438.4 777.6,454.4 764.8,468.8 748.8,468.8L273.6,468.8C265.6,468.8 257.6,465.6 252.8,460.8 248,452.8 244.8,446.4 244.8,438.4z M244.8,585.6C244.8,569.6,257.6,555.2,273.6,555.2L748.8,555.2C764.8,555.2 777.6,568 777.6,585.6 777.6,601.6 764.8,616 748.8,616L273.6,616C265.6,616 257.6,612.8 252.8,608 248,601.6 244.8,593.6 244.8,585.6z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>


    <DrawingImage x:Key="{x:Static images:XXXResources.ImageEditorKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M842.768,961.125L171.087,961.125C109.262,961.125,59.142,910.97,59.142,849.109L59.142,176.983C59.142,115.113,109.999,59.6610000000001,171.826,59.6610000000001L622.562,59.6610000000001 622.562,116.003 171.826,116.003C140.915,116.003,115.117,146.052,115.117,176.984L115.117,849.11C115.117,880.04,140.176,905.121,171.089,905.121L842.77,905.121C873.681,905.121,904.267,879.381,904.267,848.448L904.267,397.714 960.609,397.714 960.609,848.445C960.607,910.31,904.596,961.126,842.769,961.126z M508.224,689.691C500.039,697.881,489.793,701.977,479.227,704.034L234.152,825.259C206.57,838.066,184.478,813.329,194.643,785.723L315.788,540.482C317.841,529.91,321.936,519.657,330.121,511.468L765.494,75.809C787.352,53.933,822.793,53.933,844.648,75.809L943.596,174.822C965.456,196.694,965.456,232.162,943.596,254.033L508.225,689.691z M248.244,751.852C241.841,764.765,254.207,778.028,267.998,771.619L419.333,679.953 339.847,600.415 248.244,751.852z M389.485,570.876L448.857,630.287C459.783,641.224,431.538,612.955,468.644,650.086L785.278,333.243 685.625,234.936 369.7,551.074C380.212,561.591,378.558,559.942,389.487,570.876z M884.225,194.627L824.858,135.218C813.93,124.281,796.207,124.281,785.279,135.218L727.326,193.205 824.851,293.638 884.223,234.229C895.153,223.295,895.153,205.569,884.223,194.631z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageExportKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M894.6,532.3C877.1,532.3,862.9,546.5,862.9,564L862.9,815C862.9,838.3,843.9,857.3,820.6,857.3L203.7,857.3C180.4,857.3,161.4,838.3,161.4,815L161.4,233.7C161.4,210.4,180.4,191.4,203.7,191.4L474.4,191.4C491.9,191.4 506.1,177.2 506.1,159.7 506.1,142.2 492,128 474.4,128L203.7,128C145.4,128,98,175.4,98,233.7L98,815C98,873.3,145.4,920.7,203.7,920.7L820.6,920.7C878.9,920.7,926.3,873.3,926.3,815L926.3,564C926.3,546.5,912.1,532.3,894.6,532.3z" />
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M253.1,688.9C351.6,595.7 451,451.6 626.8,460.9 639.2,461.6 648.9,471.3 648.9,483.8L648.9,544.8C648.8,564,671.1,574.7,686,562.6L913.9,378.3C925.2,369.2,925.2,351.9,913.8,342.8L687,138.8C672.1,126.8,648.9,137.4,648.8,156.5L648.8,218.3C648.8,229.9 640.9,238.3 629.5,240.9 327,309.9 250.5,664.5 253.1,688.9z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageImportKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M85.9435695,516.01547589C66.37339437,516.01547589,50.54274232,531.84612796,50.54274231,551.41630306L50.54274231,831.25734679C50.54274231,896.32506353,103.39468184,949.17700309,168.46239862,949.17700307L856.41015806,949.17700307C921.4778748,949.17700307,974.32981436,896.32506354,974.32981435,831.25734679L974.32981435,183.07319301C974.32981435,118.00547627,921.47787482,65.15353671,856.41015806,65.15353673L554.50592224,65.15353673C534.93574711,65.15353673 519.10509506,80.9841888 519.10509507,100.55436387 519.10509508,120.12453894 534.93574714,135.95519105 554.50592224,135.95519107L856.41015806,135.95519107C882.3375246,135.95519107,903.52816002,157.14582648,903.52816,183.07319301L903.52816,831.25734679C903.52816,857.18471333,882.33752459,878.37534875,856.41015806,878.37534875L168.46239862,878.37534875C142.53503208,878.37534875,121.34439666,857.18471334,121.34439505,831.25734679L121.34439505,551.29165326C121.21974362,531.84612794,105.38909318,516.01547749,85.9435695,516.01547589z" />
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M54.9055192,66.02609178C175.81679492,158.26768274 328.76332413,243.52883007 318.41730843,439.60453699 317.66940316,453.44077613 306.82478344,464.28539587 292.86389452,464.28539424L224.80455836,464.28539424C203.36462012,464.16074281,191.39814411,489.0909029,204.98508205,505.6694602L410.5342496,759.70778881C420.63096408,772.29752026,439.95183795,772.29752026,450.17320386,759.58313739L677.66091208,506.66666667C690.99854715,490.08811098,679.15672099,464.16074443,657.96608558,464.036093L589.03419436,464.036093C576.0705119,464.036093 566.72170106,455.18588621 563.85473308,442.47150497 486.82053872,105.29109341 82.20404484,63.1591238 54.9055192,66.02609178z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageMoveDownKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M540.16,568.832L991.232,117.248 963.072,89.088 512,540.672 59.904,89.088 31.744,117.248 483.84,568.832 512,596.992 540.16,568.832z M60.4159999999999,427.52L32.2559999999999,455.68 484.35199999,907.264 512.512,935.424 992.256,455.168 964.096,427.008 512.512,879.104 60.4159999999999,427.52z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageMoveUpKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M483.84,455.168L32.768,906.752 60.928,934.912 512,483.328 964.096,934.912 992.256,906.752 540.16,455.168 512,427.008 483.84,455.168z M963.584,596.48L991.744,568.32 539.648,116.736 511.488,88.5760000000001 31.744,568.832 59.904,596.992 511.488,144.896 963.584,596.48z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageNewKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M856.8,565.1L136.8,565.1C96.8,565.1 64.1,532.4 64.1,492.4 64.1,452.4 96.8,419.7 136.8,419.7L856.8,419.7C896.8,419.7 929.5,452.4 929.5,492.4 929.6,532.4 896.8,565.1 856.8,565.1z M428.6,852.3L428.6,132.3C428.6,92.3 461.3,59.6 501.3,59.6 541.3,59.6 574,92.3 574,132.3L574,852.3C574,892.3 541.3,925 501.3,925 461.3,925.1 428.6,892.3 428.6,852.3z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageRenameKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M554.048823,6.418479A329.077747,329.077747,0,0,1,819.504872,307.561181L878.519482,240.868091 941.044253,292.057963 787.182125,446.651375 633.393124,291.984834 685.31428,240.794963 745.718329,301.784038A255.949359,255.949359,0,0,0,253.564276,233.408996C245.373897,233.408996,186.286159,205.620208,186.286159,205.620208A329.077747,329.077747,0,0,1,553.975695,6.418479z M76.44732,804.614835L120.543738,683.514225 322.597475,683.514225 366.693893,804.614835 443.698085,804.614835 262.705325,334.691813 181.094044,334.691813 0.101283,804.614835 76.44732,804.614835z M300.878343,624.28023L142.262869,624.28023 220.583373,411.696006 223.215995,411.696006 300.878343,624.28023z M845.757964,1024C895.777782,1024 934.608956,1014.785823 962.251486,996.357469 994.501105,973.980182 1010.954993,939.756097 1010.954992,892.368901 1010.954992,860.777437 1003.057126,835.109373 987.261395,816.022864 971.465663,796.936355 947.772065,784.4314 916.838757,778.508001 940.532355,769.95198 958.302553,756.78887 971.465663,739.676827 984.628773,721.248473 991.210328,698.871186 991.210328,672.544966 991.210328,636.346414 978.705374,608.045728 953.695465,586.984752 927.369245,564.607465 891.828849,554.076977 845.757964,554.076978L631.199273,554.076978 631.199273,1024 845.757964,1024z M826.671454,753.498092L702.938222,753.498092 702.938222,613.310972 827.987765,613.310972C859.579229,613.310972 883.272826,618.576216 897.752248,629.764859 912.231669,640.295347 919.471379,657.40739 919.471379,681.100988 919.471379,706.110897 912.231669,724.539251 897.752248,736.386049 883.272827,747.574692 859.579229,753.498092 826.671454,753.498092z M835.885631,964.766006L702.938222,964.766006 702.938222,812.073931 837.860098,812.073931C872.084184,812.073931 897.752248,817.99733 914.206135,830.502285 930.660022,843.007239 939.216044,863.41006 939.216044,891.05259 939.216044,918.036965 928.027401,937.78163 906.966425,950.286585 889.854382,959.500762 866.160784,964.766006 835.885631,964.766006z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageResetKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M918.674286,583.021714A35.108571,35.108571,0,0,0,875.885714,608.109714A377.270857,377.270857,0,0,1,160.987429,652.873143L229.888,652.873143 123.830857,511.707429 18.870857,652.873143 86.162286,652.873143 89.088,661.357714A447.634286,447.634286,0,0,0,943.762286,625.883429A35.108571,35.108571,0,0,0,918.747429,583.021714z M102.692571,444.050286A35.108571,35.108571,0,0,0,145.408,418.742857A376.758857,376.758857,0,0,1,510.976,134.875429A374.710857,374.710857,0,0,1,861.184,371.419429L791.844571,371.419429 897.901714,512.585143 1002.788571,371.419429 935.862857,371.419429A447.634286,447.634286,0,0,0,77.312,401.408A35.108571,35.108571,0,0,0,102.692571,444.050286z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageRunKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M512.00096,0.00192A510.719042,510.719042,0,0,0,0.00191999999998416,512.00096C0.00191999999998416,795.712428 228.289492,1024 512.00096,1024 795.712428,1024 1024,795.712428 1024,512.00096 1024,228.289492 795.712428,0.00192000000009784 512.00096,0.00192000000009784z M512.00096,960.00012A447.99916,447.99916,0,1,1,512.00096,64.0018A447.99916,447.99916,0,0,1,512.00096,960.00012z M759.488496,494.912992L394.68918,266.68942C381.889204,256.00144,362.68924,266.68942,362.68924,283.713388L362.68924,740.288532C362.68924,757.3125,381.889204,768.00048,394.68918,757.3125L759.488496,529.088928A18.559965,18.559965,0,0,0,759.488496,494.912992z" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>

    <DrawingImage x:Key="{x:Static images:XXXResources.ImageToolSetKey}">
        <DrawingImage.Drawing>
            <DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
                <GeometryDrawing Brush="#FF1296DB" Geometry="F1 M1024,1024z M0,0z M895.463,547.648C896.591,535.958 897.286,524.218 897.286,512.312 897.286,500.406 896.591,488.66 895.463,476.975L985.068,406.136C1004.481,390.262,1009.468,362.913,997.027,341.306L901.47,174.105C889.35,152.871,863.398,142.679,838.835,152.119L733.84,194.806C714.59,180.966,694.425,169.119,673.673,159.412L657.75,45.943C653.995,21.386,632.442,2.883,607.664,2.883L416.497,2.883C391.397,2.883,370.324,20.956,366.354,46.316L350.486,159.412C329.678,169.17,309.517,181.024,290.264,194.806L185.004,151.955C162.318,143.164,134.86,152.871,122.745,174.104L27.187,341.249C14.744,363.02,19.737,390.369,39.465,406.402L128.699,476.975C127.569,488.609 126.874,500.406 126.874,512.312 126.874,524.217 127.57,536.011 128.699,547.648L38.984,618.488C19.737,634.414,14.744,661.706,27.187,683.263L122.797,850.571C134.967,871.753,161.515,881.941,185.377,872.45L290.371,829.763C309.676,843.601,329.841,855.451,350.537,865.106L366.462,978.734C370.381,1003.669,391.454,1021.736,416.497,1021.736L607.613,1021.736C632.385,1021.736,653.888,1003.239,657.805,978.303L673.675,865.157A380.39,380.39,0,0,0,733.841,829.763L839.108,872.664C845.004,874.971 851.171,876.096 857.501,876.096 875.517,876.096 892.353,866.339 901.471,850.516L996.867,683.428C1009.361,661.871,1004.531,634.522,984.638,618.061L895.463,547.648z M858.999,822.848L740.008,774.423C731.11,770.725 721.024,772.173 713.465,778.069 689.977,796.301 664.883,811.049 638.823,821.882 630.079,825.528 623.915,833.572 622.568,842.957L605.04,968.166 419.442,970.904 401.535,842.957C400.246,833.572 394.027,825.585 385.285,821.882 359.441,811.158 334.29,796.358 310.643,778.069A27.083,27.083,0,0,0,294.233,772.494A26.518,26.518,0,0,0,284.151,774.48L169.344,823.974 72.7669999999999,660.204 173.685,580.523C181.087,574.677 184.841,565.344 183.659,556.016 181.731,541.639 180.498,527.112 180.498,512.312 180.498,497.512 181.731,482.978 183.608,468.715 184.841,459.331 181.087,450.055 173.634,444.21L73.734,367.903 165.161,201.777 284.045,250.145A26.743,26.743,0,0,0,310.587,246.549C334.132,228.318 359.334,213.519 385.394,202.579 394.135,198.933 400.246,190.944 401.591,181.56L416.497,56.5100000000001 604.719,53.7730000000001 622.626,181.669C623.916,191.052 630.135,199.041 638.874,202.687 664.828,213.519 689.978,228.267 713.573,246.549 721.188,252.395 731.269,253.791 740.115,250.196L854.923,200.755 951.557,364.416 850.583,444.211C843.181,450.055 839.371,459.331 840.553,468.659 842.38,483.031 843.719,497.562 843.719,512.364 843.719,527.164 842.429,541.697 840.553,556.069 839.371,565.401 843.181,574.678 850.583,580.523L950.427,656.722 859,822.847z M858.999,822.848 M512.16,310.146C401.59,310.146 311.661,400.828 311.661,512.312 311.661,623.739 401.59,714.472 512.16,714.472 622.733,714.472 712.607,623.795 712.607,512.312 712.607,400.828 622.677,310.146 512.16,310.146z M512.16,660.848C431.19,660.848 365.287,594.248 365.287,512.312 365.287,430.37 431.19,363.772 512.16,363.772 593.133,363.772 658.981,430.427 658.981,512.312 658.981,594.192 593.078,660.848 512.16,660.848z M512.16,660.848" />
            </DrawingGroup>
        </DrawingImage.Drawing>
    </DrawingImage>
</ResourceDictionary>

3.4 修改Generic.xaml文件

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,/XXX.IconPacks; component/Images/IconDictionary.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

3.5 编译生成资源程序集

4 使用资源程序集

4.1 新建WPF Application

4.2 添加资源程序集的引用

在这里插入图片描述

4.3 添加名称空间引用

<Window x:Class="WpfApp1.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:images="clr-namespace:XXX.IconPacks.Images;assembly=XXX.IconPacks"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

4.4 使用资源键

<Window x:Class="WpfApp1.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:images="clr-namespace:XXX.IconPacks.Images;assembly=XXX.IconPacks"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <WrapPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageCalibrationKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageCameraKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageCommunicationKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageCompileKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageDeleteKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageDescriptionKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageEditorKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageExportKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageImportKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageMoveDownKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageMoveUpKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageNewKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageRenameKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageResetKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageRunKey}}"/>
            </Button>

            <Button Margin="5">
                <Image Source="{StaticResource ResourceKey={x:Static images:XXXResources.ImageToolSetKey}}"/>
            </Button>
        </WrapPanel>
    </Grid>
</Window>

4.5 效果

在这里插入图片描述

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-11-17 12:57:47  更:2021-11-17 12:58:58 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 19:38:25-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码