Ich bin dabei, meine Xamarin.Android App auf Xamarin.iOS zu portieren, ich kann mein Fortschrittsbalken nicht aktualisieren, wo liege ich falsch?UIProgressView aktualisiert nicht von BackgroundWorker.ProgressChanged
Die Werte werden in updateProgressBar()
korrekt und progressBarValue
in diesem Beispiel wie erwartet auf 0,25 festgelegt, aber das UIProgressView wird nicht auf dem Bildschirm aktualisiert. progressBar
ist ein UIProgressView
auf dem Storyboard.
public BackgroundWorker backgroundWorker { get; private set; }
private float progressBarValue { get; set; }
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
startBackgroundWorker();
}
private void startBackgroundWorker()
{
if (backgroundWorker == null || backgroundWorker.CancellationPending) backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += (s, e) =>
{
//do stuff
backgroundWorker.ReportProgress(25);
//do stuff
};
backgroundWorker.RunWorkerCompleted += (s, e) => { //do stuff };
backgroundWorker.ProgressChanged += (s, e) => { updateProgressBar(e.ProgressPercentage); };
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.RunWorkerAsync();
}
private void updateProgressBar(float v)
{
if (v > 0){
float value = v/100;
progressBarValue = progressBarValue + value;
if (progressBarValue > 1) progressBarValue = 1;
progressBar.Progress = progressBarValue;
}
}
Ich habe auch versucht SetProgress(progressBarValue,true)
mit
private void updateProgressBar(float v)
{
if (v > 0){
float value = v/100;
progressBarValue = progressBarValue + value;
if (progressBarValue > 1) progressBarValue = 1;
progressBar.SetProgress(progressBarValue,true);
}
}
und mit InvokeOnMainThread
private void updateProgressBar(float v)
{
if (v > 0){
float value = v/100;
progressBarValue = progressBarValue + value;
if (progressBarValue > 1) progressBarValue = 1;
InvokeOnMainThread (() => {
// manipulate UI controls
progressBar.SetProgress(progressBarValue,true);
});
}
}
Was sind die Alternativen zum Down-Voting? Down-Voting sollte für Extremfälle vorbehalten bleiben. Es ist nicht als Ersatz für Kommunikation und Bearbeitung gedacht. Wenn etwas nicht stimmt, hinterlassen Sie einen Kommentar oder bearbeiten Sie den Beitrag, um ihn zu korrigieren. http://stackoverflow.com/help/privileges/vote-down – tallpaul
Ich verstehe nicht, warum Sie unten abgestimmt haben, Sie haben sogar Ihren Code +1 –