在我的 Xamarin Forms 5 應用程式中,我使用以下代碼在后面的代碼中設定了背景影像:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyPage : ContentPage
{
public MyPage()
{
InitializeComponent();
this.BackgroundImageSource = "my_bg_image.jpg";
}
}
如何在后面的代碼中設定影像縱橫比?我需要將其設定為AspectFill.
uj5u.com熱心網友回復:
正如@ToolmakerSteve 提到的,沒有辦法設定Aspect為BackgroundImageSource. 以下代碼在正確設定背景影像和處理覆寫 iOS 上的表單元素問題的鍵盤方面都可以正常作業。
<RelativeLayout>
<Image
Source="my_background_image.jpg"
Aspect="AspectFill"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"/>
<ScrollView
Orientation="Neither"
Padding="0"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}">
// Place my form elements here. In my case, I use Grid
</ScrollView>
</RelativeLayout>
uj5u.com熱心網友回復:
您可以設定xaml 中任何元素的任何屬性,方法是給該元素一個x:Name.
<Image x:Name="myImage" ... />
C#:
myImage.Aspect = Aspect.AspectFill;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/487696.html
