如何在大型项目中重用图标(xaml-paths)? [英] How to reuse icons (xaml-paths) in a large project?

查看:75
本文介绍了如何在大型项目中重用图标(xaml-paths)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个大型Silverlight 4项目开发的一部分,我们将在其中的GUI的不同部分使用一组符号(请参见下面的示例).

I am part of the development of a larger-scale Silverlight 4 project, where we will have a set of symbols that should be used across different parts of the GUI (see the example below).

这些图标是直接从Blend中的多个路径制成的,将在用户控件中单独使用或用作不同的视觉状态(在多个上下文中使用相同的图标).为了便于更改单个图标的设计并使其在整个应用程序中传播,存储这些图标的最佳方法是什么?

These icons are made from multiple paths directly in Blend, and will be used, either singly or as different visual states in usercontrols (with the same icon used in more than one context). In order to facilitate changing the design of a single icon, and having it propagate throughout the application, what is the best way to store these?

我尝试从中创建样式(右键单击->编辑样式..),但这仅允许我创建一个空样式,而没有任何路径数据.手动将包含路径的网格的xaml代码放入字典中也没有帮助,我还缺少什么?

I have tried creating styles from them (right click -> edit style..), but this only allows me to create an empty style, without any path data. manually putting the xaml code for the grid containing the paths into a dictionary hasn't helped either, what am I missing?

我如何轻松地保存路径和样式(颜色,笔触,填充等)信息,最好是保存在资源字典中,这样我就可以轻松地在用户控件和其他地方重用它们,同时保持易于更新的内容?

How do I save the path and style (colour, stroke, fill, etc) information in an easy way, preferably in a resource dictionary, so I can easily reuse them in usercontrols and elsewhere, while maintaining the easy updating?

我要重用的图标示例:

推荐答案

<Style x:Key="MyIcon" TargetType="ContentControl">
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Path Stretch="Fill" Fill="Red" Data="F1 M 24,13C 27.1521,13 29.9945,14.3258 32,16.4501L 32,11L 35,14L 35,22L 27,22L 24,19L 29.5903,19C 28.217,17.4656 26.2212,16.5 24,16.5C 20.1969,16.5 17.055,19.3306 16.5661,23L 13.0448,23C 13.5501,17.3935 18.262,13 24,13 Z M 24,31.5C 27.8031,31.5 30.945,28.6694 31.4339,25L 34.9552,25C 34.4499,30.6065 29.738,35 24,35C 20.8479,35 18.0055,33.6742 16,31.5499L 16,37L 13,34L 13,26L 21,26L 24,29L 18.4097,29C 19.783,30.5344 21.7787,31.5 24,31.5 Z "/>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

然后使用contentcontrol类型(或派生)的样式:

And then use style with contentcontrol type (or derivates):

<ContentControl Style="{StaticResource MyIcon}" Width="20" Height="20" Grid.Row="0"/>

所有样式都可以在某些资源字典中: 这是内容丰富的文章: http://blogs. infosupport.com/tips-for-use-of-use-of-usage-of-resource-dictionaries-in-silverlight-and-wpf/

All styles can be inside some resource dictionary: This is quite informative article: http://blogs.infosupport.com/tips-for-effective-usage-of-resource-dictionaries-in-silverlight-and-wpf/

这篇关于如何在大型项目中重用图标(xaml-paths)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆