xamarin,如何将内容顺利上传到StackLayout [英] xamarin, How to smoothly upload content to StackLayout
问题描述
我有一个大型数据库,我需要从我的应用程序中组织搜索帐户.应用会动态加载数据. NetworkBackgroundWorker 是一个类,用于将请求者发送到服务器(带有数据库).此类使用 BackgroundWorker 在后台等待答案.
I have a large database and I need to organize searching accounts from my application. App is loaded data dynamically. NetworkBackgroundWorker is a class that send requeste to the server (with database). This class uses BackgroundWorker for waiting answer in the background.
//Callback method
Action<string> refToSP = SetParticipants;
//Send a request to the server for getting account data
NetworkBackgroundWorker.InvokeService(
query,
requestURL,
methodName,
refToSP);
SetParticipants 方法正在使用另一个 BackgroundWorker 在后台向 mainStackLayout 中添加新帐户.
The SetParticipants method is using another BackgroundWorker for add new accounts to the mainStackLayout in the background.
//SetParticipants - This is a method that will be call from the BackgroundWorker
//participantsJSON - Data represented as a JSON code
public void SetParticipants(string participantsJSON)
{
backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork +=
new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerAsync(participantsJSON);
}
以及向 MainStackLayout
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
List<ParticipantsTable> participantsTable =
JsonSerializer.Deserialize<List<ParticipantsTable>>(e.Argument.ToString());
for (int i = 0; i < participantsTable.Count; i++)
{
BoxView boxView = new BoxView();
boxView.BackgroundColor = Color.LightGreen;
Label labelParticipantName = new Label();
labelParticipantName.Text =
participantsTable[i].FirstName_ + " " + participantsTable[i].LastName_;
labelParticipantName.FontSize = 20;
labelParticipantName.VerticalOptions = LayoutOptions.StartAndExpand;
labelParticipantName.HorizontalOptions = LayoutOptions.StartAndExpand;
Label labelParticipantPhone = new Label();
labelParticipantPhone.Text =
participantsTable[i].PhoneNumber_;
labelParticipantPhone.FontSize = 20;
labelParticipantPhone.VerticalOptions = LayoutOptions.StartAndExpand;
labelParticipantPhone.HorizontalOptions = LayoutOptions.StartAndExpand;
Label labelSelect = new Label();
labelSelect.Text = "Select: ";
labelSelect.FontSize = 20;
labelSelect.VerticalOptions = LayoutOptions.Start;
labelSelect.HorizontalOptions = LayoutOptions.Start;
CheckBox checkBox = new CheckBox();
checkBox.VerticalOptions = LayoutOptions.Start;
checkBox.HorizontalOptions = LayoutOptions.Start;
StackLayout stackLayout = new StackLayout();
stackLayout.Orientation = StackOrientation.Horizontal;
stackLayout.Children.Add(labelSelect);
stackLayout.Children.Add(checkBox);
var container = new Grid();
container.Children.Add(boxView, 0, 0);
container.Children.Add(labelParticipantName, 0, 0);
container.Children.Add(labelParticipantPhone, 0, 1);
container.Children.Add(stackLayout, 0, 2);
Grid.SetRowSpan(boxView, 3);
mainStackLayout.Children.Add(container);
}
}
我不知道为什么,但是在应用程序中滚动无法顺利进行.
I do not have idea why, but scrolling is working not smoothly in the app.
https://www.youtube.com/watch?v=x1iEHFPINnE
如何使滚动平滑?
推荐答案
@Lucas Zhang-将容器放入ScrollView或ListView中而不是StackLayout中". 该建议有助于消除滚动跳动.
@Lucas Zhang - "Put container in the ScrollView or ListView instead of StackLayout". This recommendation helped to get rid of the scroll jumping.
这篇关于xamarin,如何将内容顺利上传到StackLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!