【发布时间】:2017-12-31 01:44:04
【问题描述】:
伙计们,我在尝试将图像作为特定页面的背景时遇到了一些麻烦。我试图通过这里提到的嵌入式方法来做到这一点:https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Embedded_Images .由于某种原因,当我运行该应用程序时,它崩溃了。我认为'BackgroundImage ='行出了点问题,因为当我这样做时我有点猜到了。当我注释掉该行时,应用程序加载正常,只是没有背景图像。我使用 build action = content 并作为设置复制到输出目录...
public class LoginPage : ContentPage
{
Entry emailBox = new Entry();
Entry passwordBox = new Entry();
Button createAccount = new Button();
Button forgotPassword = new Button();
StackLayout layout = new StackLayout();
Image embeddedImage = new Image { Source = ImageSource.FromResource("Charity.Properties.hands-426x640.jpg") };
public LoginPage()
{
Title = "Login";
BackgroundColor = Color.LightPink;
BackgroundImage = "Charity.Properties.hands-426x640.jpg";
emailBox.Placeholder = "email";
emailBox.BackgroundColor = Color.LightPink;
emailBox.PlaceholderColor = Color.HotPink;
passwordBox.Placeholder = "password";
passwordBox.BackgroundColor = Color.LightPink;
passwordBox.PlaceholderColor = Color.HotPink;
passwordBox.IsPassword = true;
createAccount.Text = "create an account";
createAccount.TextColor = Color.HotPink;
createAccount.Font = Font.SystemFontOfSize(NamedSize.Medium);
createAccount.BorderWidth = 0;
createAccount.HorizontalOptions = LayoutOptions.Center;
createAccount.VerticalOptions = LayoutOptions.CenterAndExpand;
forgotPassword.Text = "recover password";
forgotPassword.TextColor = Color.HotPink;
forgotPassword.Font = Font.SystemFontOfSize(NamedSize.Medium);
forgotPassword.BorderWidth = 0;
forgotPassword.HorizontalOptions = LayoutOptions.Center;
forgotPassword.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.VerticalOptions = LayoutOptions.End;
layout.BackgroundColor = Color.LightPink;
layout.Children.Add(emailBox);
layout.Children.Add(passwordBox);
layout.Children.Add(createAccount);
layout.Children.Add(forgotPassword);
Content = layout;
}
}
【问题讨论】:
-
查看您用于嵌入图像的路径,然后查看您用于背景的路径。提示提示。
-
@Nkosi 我试着把它改成这个 BackgroundImage = "Charity.Properties.hands-426x640.jpg";但是应用程序在运行时仍然崩溃。该链接在 xaml 中,对吗?我还没学过xaml,到目前为止我只学过c#..
-
在 Droid 项目中,我将图像的构建操作设置为 AndroidResource。
标签: c# xamarin.forms