【发布时间】:2017-07-18 20:26:14
【问题描述】:
我有以下简单的 XAML 页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.UserGuides.VPN">
<ContentPage.Content>
<ScrollView>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center" Margin="10,10,10,10">
<Label Margin="10,10,10,10" Text="How to connect to VPN." HorizontalOptions="Center" />
<Label Margin="10,10,10,10" Text="If you have a corporate notebook, look for the Cisco AnyConnect application. Either in your start menu, on your desktop, or in your taskbar." />
<Image x:Name="imgVPN1" Margin="10,10,10,10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
<Label Margin="10,10,10,10" Text="Select your region and press the Connect button." />
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
在构造函数中,我调用了一个加载图片的方法:
private void LoadImages()
{
imgVPN1.Aspect = Aspect.AspectFit;
ImageSource imagesrc = ImageSource.FromResource("Test.Files.CiscoAnyConnect.PNG");
imgVPN1.Source = imagesrc;
}
在我的(相当大的、高 DPI)手机上的结果如下所示:
当然,我希望图像自动展开,以便占据整个屏幕宽度。在保持纵横比的同时。但我怎样才能做到这一点?我已经尝试将 Aspect 设置为“AspectFill”,并添加了
imgVPN1.WidthRequest = Application.Current.MainPage.Width;
到 LoadImages 方法,但这使得最终结果看起来像这样:
我一直在玩弄各种 HorizontalOptions、VerticalOptions、Aspects、GridView、StackLayouts,... 最终的结果总是第一个或第二个屏幕截图。那么我怎样才能在这里实现我想要的呢?
【问题讨论】:
-
你要试验的图片尺寸是多少?
-
@YuriS CiscoAnyConnect.PNG 图像的尺寸是 411x 191。如果我能得到这些值,将 HeightRequest 设置为纵横比很容易,但似乎几乎不可能做到使用我过去几个小时研究的 Xamarin.Forms。
-
你能把它贴在某个地方,这样我就不需要纠正类似的事情了吗?
-
创建了 2 个错误。一个用于网格,一个用于 StackLayout。已确认但未修复的错误。如果您需要缩放图片,我会尝试使用相对布局。对不起bugzilla.xamarin.com/show_bug.cgi?id=27729 和bugzilla.xamarin.com/show_bug.cgi?id=55294
标签: xamarin.forms