c# – 如何在Windows 8应用程序中使用xaml矢量图像作为图像源

c# – 如何在Windows 8应用程序中使用xaml矢量图像作为图像源,第1张

概述我在Inkscape中创建了一些资源,并希望将它们用作 Windows 8应用程序中的图标.我已经做了一些阅读,接缝,而.Net 4.5支持SVG, the modern ui profile does not.我将svg转换为xaml使用 this tool. 我得到以下xaml. <Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/ 我在Inkscape中创建了一些资源,并希望将它们用作 Windows 8应用程序中的图标.我已经做了一些阅读,接缝,而.Net 4.5支持SVG,the modern ui profile does not.我将svg转换为xaml使用 this tool.

我得到以下xaml.

<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:name="svg2997" WIDth="744.09448" Height="1052.3622" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">  <Canvas x:name="layer1">    <Path Fill="#FFCCCCCC" stroke="#FF000000" strokeThickness="1.34377062" strokeMiterlimit="4" x:name="path3007" Data="M372.58272,134.72445C167.96301,134.72445 2.06820310000001,300.58818 2.06820310000001,505.20789 2.06820310000001,709.8276 167.96301,875.72241 372.58272,875.72241 577.20243,875.72241 743.06616,709.8276 743.06616,505.20789 743.06616,300.58818 577.20243,134.72445 372.58272,134.72445z M280.73888,251.77484L455.94149,251.77484 455.94149,413.70594 628.16035,588.97071 455.94149,773.71514 280.73888,588.97071 106.22005,413.70594 280.73888,251.77484z" />  </Canvas></Canvas>

如果我直接将它添加到我的应用程序xaml,它会呈现,但是缩放比例是关闭的.

如果可能,我想使用它作为图像对象的图像源.

<Image HorizontalAlignment="left" Height="100" margin="127,37,0" VerticalAlignment="top" WIDth="100" Source="Assets/plus_circle.xaml"/>

这可以做吗

解决方法 大多数Appbar按钮都是基于StandardStyles中包含的一种称为AppbarbuttonStyle的样式.

要自定义按钮的文本,您可以设置automationPropertIEs.name附加属性,以自定义按钮中的图标,您可以设置Content属性,并且为了辅助功能的原因设置automationPropertIEs.automationID附加属性也是一个好主意.

以下是使用此方法定制的按钮的示例:

<Style x:Key="FolderbuttonStyle" targettype="buttonBase" BasedOn="{StaticResource AppbarbuttonStyle}">    <Setter Property="automationPropertIEs.automationID" Value="FolderAppbarbutton"/>    <Setter Property="automationPropertIEs.name" Value="Folder"/>    <Setter Property="Content" Value="&#xE188;"/></Style>

如上所述,要自定义图标,您可以设置Content属性.挑战是如何设置内容,以显示您的自定义矢量图.

事实证明,您可以将Xaml甚至您的任何路径放入VIEwBox以更改其比例.这是我的第一个方法,但它不起作用.事实上,似乎任何时候你使用Xaml扩展符号来设置一个不起作用的按钮的Content属性.

<Style x:Key="SquarebuttonStyle" targettype="buttonBase" BasedOn="{StaticResource AppbarbuttonStyle}"><Setter Property="automationPropertIEs.automationID" Value="SquareAppbarbutton"/><Setter Property="automationPropertIEs.name" Value="Square"/><Setter Property="Content">    <Setter.Value>        <!-- This square will never show -->        <Rectangle Fill="Blue" WIDth="20" Height="20" />    </Setter.Value></Setter>

我实际上认为这是一个错误,但幸运的是有一个解决方法.

Tim Heuer写了一篇关于使用Xaml Path作为按钮的艺术品的最简单的方法的优秀文章.那篇文章在这里:

http://timheuer.com/blog/archive/2012/09/03/using-vectors-as-appbar-button-icons.aspx

简而言之,您需要定义一个正确设置所有绑定的样式:

<Style x:Key="PathAppbarbuttonStyle" BasedOn="{StaticResource AppbarbuttonStyle}" targettype="buttonBase"><Setter Property="ContentTemplate">    <Setter.Value>        <DataTemplate>            <Path WIDth="20" Height="20"                 Stretch="Uniform"                 Fill="{Binding Path=Foreground,relativeSource={relativeSource Mode=TemplatedParent}}"                 Data="{Binding Path=Content,relativeSource={relativeSource Mode=TemplatedParent}}"/>        </DataTemplate>    </Setter.Value></Setter>

然后,您创建一个继承自该样式的样式,并粘贴到您的路径中.以下是您上面列出的作品的风格:

<Style x:Key="CrossbuttonStyle" targettype="buttonBase" BasedOn="{StaticResource PathAppbarbuttonStyle}">    <Setter Property="automationPropertIEs.automationID" Value="CrossAppbarbutton"/>    <Setter Property="automationPropertIEs.name" Value="Cross"/>    <Setter Property="Content" Value="M372.58272,251.77484z"/></Style>

最后,您可以在Appbar中使用它:

<button Style="{StaticResource CrossbuttonStyle}" />

开发支持,设计支持和更好的善良方式:
http://bit.ly/winappsupport

总结

以上是内存溢出为你收集整理的c# – 如何在Windows 8应用程序中使用xaml矢量图像作为图像源全部内容,希望文章能够帮你解决c# – 如何在Windows 8应用程序中使用xaml矢量图像作为图像源所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1244072.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存