【发布时间】:2019-11-14 23:24:59
【问题描述】:
在我的 Xamarin Forms 项目中,我有几个应该显示的 SVG 图像。
因此我使用 Xamarin.Forms.FFImageLoading.Svg.Forms NuGet 包。
XAML 如下所示:
<Grid
Margin="0"
ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<local:LetterSpacingLabel
FontSize="14"
TextColor="#1F1F1F"
FontFamily="{StaticResource Bliss2-Regular}"
LetterSpacing="0.1"
VerticalTextAlignment="Center"
Grid.Column="0"
Text="{Binding Name}"/>
<ffimageloadingsvg:SvgCachedImage
Grid.Column="1"
Source="{Binding StateIconPath}"/>
</Grid>
并且图像会按应有的方式显示。
但是我希望它更小,所以我像这样添加 LayoutOptions:
之后,图像不再显示。
有解决这个问题的办法吗?
提前致谢。
[编辑]
这是我正在使用的 .svg 文件:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 22 22" style="enable-background:new 0 0 22 22;" xml:space="preserve">
<style type="text/css">
.st0{fill:#CE2D46;}
</style>
<path id="Pfad_73" class="st0" d="M11,0C4.9,0,0,4.9,0,11s4.9,11,11,11c6.1,0,11-4.9,11-11c0,0,0,0,0,0C22,4.9,17.1,0,11,0z
M12.4,18.6c0,0.7-0.6,1.3-1.3,1.3h-0.2c-0.7,0-1.3-0.6-1.3-1.3v-0.2c0-0.7,0.6-1.3,1.3-1.3h0.2c0.7,0,1.3,0.6,1.3,1.3V18.6z
M12.4,14.2c0,0.8-0.7,1.3-1.4,1.3c-0.7,0-1.2-0.6-1.3-1.3V4.9c0-0.8,0.7-1.3,1.4-1.3c0.7,0,1.2,0.6,1.3,1.3V14.2z"/>
</svg>
【问题讨论】:
-
嗯,我不认为 LayoutOptions 会使图像变小!为什么不把它放在带有自动行/列的网格中!?
-
@G.hakim 你能详细解释一下吗?我有另一个解决方案,其中 LayoutOptions 成功了,但我无法让它在这里工作。
-
如果您阅读了 LayoutOptions 的 Xamarin 文档,那么您将了解 LayoutOptions 仅在可用时才能占用更多空间并且您需要为此使用它的 Expand 版本这一事实,但是一般来说,LayoutOptions 更多的是关于对齐而不是扩展......此外,它可能由于多种原因而无法正常工作,它可能是一个错误,或者可能是图像本身具有某种对齐方式,这使得它如果我说的有道理,就这样吧。
-
@G.hakim 谢谢你,从现在开始我会尝试正确使用 LayoutOptions。但是我仍然很困惑,为什么完全相同的代码会在一个解决方案中工作,而在另一个解决方案中却不行?
-
如果可能,您能否添加此处未显示的图像?
标签: xaml svg xamarin.forms ffimageloading