XAML图标 - 如何使用? [英] XAML Icons - How to use?

查看:117
本文介绍了XAML图标 - 如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些XAML格式的矢量图形文件,我想将它们用作Silverlight应用程序中的图标/按钮。
我喜欢的方法是使用Image控件并将其源属性设置为.xaml文件,就像我可以使用常规位图图像一样。



<但它并不那么容易,我试图将它们作为ControlTemplates包含在资源字典中,我甚至尝试创建一个可以动态加载Xaml的自定义控件,但我并不满意结果,因为我需要包装他们在ViewBox的控制,以允许动态大小等。

所以我的问题是,如果任何人有任何最佳实践建议如何最好地使用我的xaml图标?
我可以在需要时复制粘贴xaml,但我真的不喜欢这种方法。



预先感谢。


您应该发布一些XAML图标的例子来澄清,但是任何内容控件,比如按钮 ContentControl 均具有 Content ContentTemplate 属性。下面显示了一个共享的 ContentTemplate 示例:

 < UserControl 
xmlns =http ://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
xmlns:sdk = http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk
xmlns:toolkit =http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit
>
< UserControl.Resources>
< Style x:Key =MyTriangleIconTargetType =ContentControl>
< Setter Property =ContentTemplate>
< Setter.Value>
< DataTemplate>
<网格>
< Polygon Fill =BlackStroke =Black>
< Polygon.Points>
< Point X =0Y =100/>
< Point X =100Y =0/>
< Point X =100Y =100/>
< / Polygon>
< Polygon Fill =RedStroke =Red>
< Polygon.Points>
< Point X =100Y =0/>
< Point X =0Y =100/>
< Point X =0Y =0/>
< / Polygon>
< / Grid>
< / DataTemplate>
< / Setter>
< / style>
< /UserControl.Resources>

< StackPanel Background =White>

您可以将上述内容粘贴到我的 XamlViewer ,以便快速查看结果。

Jim McCurdy


I have some vector graphic files in XAML format and I would like to use them as icons/buttons in an Silverlight application. The approach I would have preferred is to use an Image control and set its source property to the .xaml file, much like I can use a regular bitmap image.

But its not that easy and I have tried to include them as ControlTemplates in resource dictionary's and I even tried to create a custom control that would load the Xaml dynamically but I wasn't really pleased with the result, since I needed to wrap them in ViewBox controls to allow dynamic size etc.

So my questions is if any one has any best practice advices how to best use my xaml icons? I could copy-paste the xaml when needed but I really dont like that approach.

Thanks in advance.

解决方案

JWendel,

You should post some examples of your XAML icons to clarify, but any content control, like Button's and ContentControl's, have both Content, and ContentTemplate properties. A shared ContentTemplate example is shown below:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
>
    <UserControl.Resources>
        <Style x:Key="MyTriangleIcon" TargetType="ContentControl">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <Polygon Fill="Black" Stroke="Black">
                                <Polygon.Points>
                                    <Point X="0" Y="100"/>
                                    <Point X="100" Y="0"/>
                                    <Point X="100" Y="100"/>
                                </Polygon.Points>
                            </Polygon>
                            <Polygon Fill="Red" Stroke="Red">
                                <Polygon.Points>
                                    <Point X="100" Y="0"/>
                                    <Point X="0" Y="100"/>
                                    <Point X="0" Y="0"/>
                                </Polygon.Points>
                            </Polygon>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <StackPanel Background="White">
        <Button Width="120" Height="120" Style="{StaticResource MyTriangleIcon}" />
        <Button Width="120" Height="120" Style="{StaticResource MyTriangleIcon}" />
    </StackPanel>

</UserControl>

You can paste the above content into my XamlViewer to quickly see the results.

Good luck,
Jim McCurdy

这篇关于XAML图标 - 如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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