私は非常に単純なページ (スタックレイアウトのボタンとアクティビティインジケーター) を持っています。INotifyPropertyChanged で作成した通知クラスを使用して、バインディングを使用して activityindicator をアクティブ化/非アクティブ化しようとしています。
ボタンを押すと、 activityindicator を表示して実行したいと思います。
ボタンクリック イベントのコードが実行されます (これは ftp です... 非同期で実行したいのですが、今のところ成功していません)。「バインド」プロパティ (Visible および Running of Notification クラス) はステータスを変更するようですが、activityindicator表示されません。
それがバインディングの問題なのか、レイアウトの問題なのか、他に何があるのか わかりません。誰でも私を助けることができますか?
これはページです
using System;
using Xamarin.Forms;
using FlagFtp;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Geco
{
public class PageFtp: ContentPage
{
private Notification _notification = new Notification ();
public PageFtp ()
{
this.Title = "Carico database";
var stacklayout = new StackLayout ();
stacklayout.HorizontalOptions = LayoutOptions.Center;
stacklayout.VerticalOptions = LayoutOptions.Center;
var activityIndicator = new ActivityIndicator ();
activityIndicator.IsEnabled = true;
activityIndicator.SetBinding (ActivityIndicator.IsVisibleProperty, "Visible");
activityIndicator.SetBinding (ActivityIndicator.IsRunningProperty, "Running");
activityIndicator.BindingContext = _notification;
bool okFtp = true;
string errorFtp = "";
// Verifico se ho il database
var filename = DependencyService.Get<IFiles> ().GetFileName (App.DB_FILENAME);
#if DEBUG
DependencyService.Get<IFiles>().Delete(filename);
#endif
var buttonRetry = new Button ();
buttonRetry.Text = "Procedere con il carico del database";
buttonRetry.Clicked += (object sender, EventArgs e) =>{
okFtp = ftp (filename, ref errorFtp);
if(okFtp)
DependencyService.Get<IOpenActivity>().OpenActivity(App.EnumForms.Login);
else{
DisplayAlert("Errore",errorFtp,"OK");
}
};
stacklayout.Children.Add (buttonRetry);
stacklayout.Children.Add (activityIndicator);
this.Content = stacklayout;
}
private bool ftp(string filename, ref string error) {
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential ();
credentials.UserName = "alessandro";
credentials.Password = "ireland";
bool ok = false;
try
{
_notification.Visible = true;
_notification.Running = true;
FlagFtp.FtpClient ftpClient = new FtpClient (credentials);
string uri = "ftp://192.168.0.102/GECOl.sqlite";
FtpFileInfo ftpFileInfo = ftpClient.GetFileInfo (new Uri (uri));
FtpStream ftpstream = ftpClient.OpenRead (ftpFileInfo);
byte[] buffer = new byte[ftpFileInfo.Length];
ftpstream.Read (buffer, 0,(int) ftpFileInfo.Length);
DependencyService.Get<IFiles> ().SaveBytes (filename, buffer);
ok = true;
}
catch(Exception ex) {
error = ex.Message;
}
finally {
_notification.Visible = false;
_notification.Running = false;
}
return ok;
}
public class Notification : INotifyPropertyChanged
{
private bool _visible = false ;
public bool Visible {
get { return _visible; }
set {
if (value.Equals (_visible))
return;
_visible = value;
OnPropertyChanged ();
}
}
private bool _running = false;
public bool Running {
get { return _running; }
set {
if (value.Equals (_running))
return;
_running = value;
OnPropertyChanged ();
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName]String propertyName=null)
{
var handler=PropertyChanged;
if(handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
}