我有一个大型数据库,我需要从我的应用程序中组织搜索帐户。应用会动态加载数据。 NetworkBackgroundWorker是将请求者发送到服务器(带有数据库)的类。此类使用BackgroundWorker在后台等待答案。
//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。
//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);
}
}
我不知道为什么,但是在应用程序中滚动无法正常进行。
https://www.youtube.com/watch?v=x1iEHFPINnE
如何使滚动平滑?
@@ Lucas Zhang-“将容器放入ScrollView或ListView中,而不要使用StackLayout”。此建议有助于消除滚动跳动。