jmw*_*jmw 7 silverlight graphics xaml vector-graphics
我有一些XAML格式的矢量图形文件,我想将它们用作Silverlight应用程序中的图标/按钮.我更喜欢的方法是使用Image控件并将其source属性设置为.xaml文件,就像我可以使用常规位图图像一样.
但它并不那么容易,我试图将它们作为ControlTemplates包含在资源字典中,我甚至尝试创建一个自动加载Xaml的自定义控件,但我对结果并不满意,因为我需要将它们包装起来ViewBox控件允许动态大小等.
所以我的问题是,如果有人有任何最佳实践建议如何最好地使用我的xaml图标?我可以在需要时复制粘贴xaml,但我真的不喜欢这种方法.
提前致谢.
JWendel,
您应该发布一些XAML图标的示例以澄清,但任何内容控件(如Button和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="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>
Run Code Online (Sandbox Code Playgroud)
您可以将上述内容粘贴到我的XamlViewer中以快速查看结果.
祝你好运,
Jim McCurdy