我有这个代码来创建我的页面,但由于某种原因,图像操作系统占用整个页面而不显示任何其他内容 这是我得到的图片。尽管图像在stacklayout内部,图像仍然位于所有其他内容之上
namespace GarageSale.Views
{
public class abcChapterPage : basePage
{
myDataTypes.abcChapter abc;
StackLayout baseStack;
#region Views
Label lblName = new Label
{
Text = "",
VerticalOptions = LayoutOptions.StartAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
Label lblSchool = new Label
{
Text = "",
VerticalOptions = LayoutOptions.StartAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
Label lblLocation = new Label
{
Text = "",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
Image profImg = new Image
{
Scale = .1f,
Aspect = Aspect.AspectFit,
};
Button viewItems = new Button
{
Text = " View Items ",
BorderRadius = 0,
//Margin = 0,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
Button viewMembers = new Button
{
Text = "View Members",
BorderRadius = 0,
//Margin = 0,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
#endregion
public abcChapterPage(myDataTypes.abcChapter o)
{
abc = o;
populateProfileFields();
}
public abcChapterPage()
{
shouldGetChapter = true;
abcid = int.Parse(App.CredManager.GetAccountValue("abc_chapter_id"));
}
StackLayout makeGUI()
{
viewItems.Command = new Command(() =>
{
Navigation.PushAsync(new viewListPage(new itemListView(), abc.id, 1, "Items for sale by " + abc.school));
});
viewMembers.Command = new Command(() =>
{
Navigation.PushAsync(new viewListPage(new userListView(), abc.id, 2, " abc Members " + abc.school));
});
#region basestack
return new StackLayout
{
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
Children = {
//lblName,
profImg,
lblSchool,
lblLocation,
new StackLayout {
Orientation = StackOrientation.Horizontal,
Padding = 0,
// Margin = 0,
Spacing = 0,
Children = {
viewItems,
viewMembers
}
}
}
};
#endregion
}
public void populateProfileFields()
{
baseStack = makeGUI();
Title = abc.school + " abc";
lblSchool.Text = abc.school;
lblLocation.Text = abc.city +", "+ abc.state;
profImg.Source = ImageSource.FromStream(() => new MemoryStream(abc.picture));
Content = baseStack;
//TODO: do this if user is admin
//if (Constants.AdminUsers.Contains(App.CredManager.GetAccountValue("G_id")) && !adminAlert)
//{
// await Task.Delay(5000);
// DisplayAlert("Admin Notice:", "You are logged in as an administrative user!", "Dismiss");
// adminAlert = true;
//}
}
bool shouldGetChapter = false;
int abcid;
protected async override void OnAppearing()
{
if (shouldGetChapter)
{
abc = await App.MANAGER.YSSI.GetabcChapter(abcid);
populateProfileFields();
}
}
}
答案 0 :(得分:0)
由于默认TextColor像背景颜色一样黑,因此不可见。
图像居中的原因可能是您应删除的Scale = .1f,
。
答案 1 :(得分:0)
你可能误解了在Xamarin.Forms中使用Aspect,Image控件要么在不保持纵横比的情况下填充容器,要么剪切图像,要么将其装箱。它没有自己调整大小,图像保持其宽高比。
在您的情况下,您图片的容器是整个StackLayout
,因此图片会覆盖其他控件。如果你想调整图像的大小,有很多方法,除了改变图像源本身,这里最简单的方法应该是为图像控件设置一个固定的大小,但是如果你想为大多数不同的尺寸创建一个适应的布局在这种情况下,我建议设置Xamarin.Forms.Grid,并为其设置RowDefinitions
和ColumnDefinitions
。