如何.svg在C#中的WPF窗口中添加文件作为图像(,png|| ,jpg)?
我用的是代码
<Image HorizontalAlignment="Left" Height="53" Margin="34,39,0,0"
VerticalAlignment="Top" Width="71"
Source="Test.svg" Name="MyImage"/>
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
Blend不支持format svg.
我发现我可以将.svg文件更改为.xaml文件.但我仍然不知道如何将xaml添加为图像.
基于答案,我改变了我的代码:
<Window x:Class="NIA_UI_Demo_CSharp.ShareDocumentsWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ShareDocumentsWin" Height="350" Width="569">
<ResourceDictionary>
<Style x:Key="TheAwesomeXAMLimage" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
my code
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<Grid Margin="0,0,2,3">
<ContentControl Style="{StaticResource TheAwesomeXAMLimage}"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
内容设置不止一次;
Ber*_*ndK 15
据我所知,你不能直接包含svg文件.两种选择:
我更喜欢第二个选项,所以我编写了一个工具,可以将单个svg转换为xaml,也可以批量转换一堆svg文件.工作流程是:只需将svg文件放入images-folder,调用批处理转换器并找到使用新图标/图像更新的images.xaml文件(资源字典).
请参阅https://github.com/BerndK/SvgToXaml
| 归档时间: |
|
| 查看次数: |
15022 次 |
| 最近记录: |