c# - 在 WPF 应用程序中添加 XAML 矢量图形
问题描述
我使用 inkscape 将 .svg 文件转换为 .xaml,生成的文件是画布。我将整个画布添加到文件 ImageResources.xaml 中的资源中:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas x:Key="xamltest" Name="svg2" Width="9354.3341" Height="5977.5567">
<Canvas.RenderTransform>
<TranslateTransform X="0" Y="0"/>
...
...
...
</Canvas>
</ResourceDictionary>
然后我将资源文件合并到资源字典中:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/AP_PlugIn;component/Resources/BrushLists.xaml" />
<ResourceDictionary Source="/AP_PlugIn;component/Resources/System/ConverterResources.xaml" />
<ResourceDictionary Source="/AP_PlugIn;component/Resources/ImageResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
最后,我尝试使用 ContentControl 在 Grid 中显示画布,但图像没有出现。有什么问题?我没有收到任何错误,我的项目正确启动
<Grid>
<ContentControl Content="{StaticResource xamltest}" Width="1253" Height="637" />
</Grid>
解决方案
查看画布的尺寸,我怀疑图像的可见部分正在从屏幕上绘制出来。
尝试将画布换成网格,而不指定其大小。
以下最小的概念证明工作正常
<Window.Resources>
<Grid x:Key="MyImage">
<Path
Data="M 0,0 M 100,100 M 25,50 L 50,25 L 75,50 L 50,75 z"
Stretch="Fill"
Stroke="Blue"
StrokeThickness="5" />
<Path
Data="M 0,0 M 100,100 M 25,25 L 25,75 L 75,75 L 75,25 z"
Stretch="Fill"
Stroke="Black"
StrokeThickness="10" />
</Grid>
</Window.Resources>
<Grid
Margin="16"
Background="AliceBlue">
<ContentControl Content="{StaticResource MyImage}" />
</Grid>
推荐阅读
- javascript - 从函数编号属性返回多个元素
- android - 自动调整图像视图以适应小屏幕尺寸
- xquery - 在 MarkLogic 中使用 XQuery 调用 java 函数
- reactjs - 如何右对齐这些项目?
- android - 从模板创建 React Native 项目时如何设置显示名称?
- swift - 如何在 Swift 中使 UITabBar 模糊
- kotlin - IntelliJ 错误:Kotlin:模块已编译
- mobaxterm - 录制 MobaXterm 宏时如何使用“等待模式”?
- c# - .NET Core 2.2 的 MassTransit
- vb.net - 如何将批处理文件嵌入到 vb.net 中的表单中