2014-12-28 2 views
0

아주 간단한 페이지 (스택 레이 아웃의 단추와 activityindicator)가 있습니다. INotifyPropertyChanged로 작성한 알림 클래스를 사용하여 activityindicator를 활성화/비활성화하기 위해 바인딩을 사용하려고합니다.Xamarin.Forms ActivityIndicator 및 Binding

버튼을 누르면 activityindicator를 표시하고 실행하고 싶습니다.

buttonclick 이벤트의 코드가 실행됩니다 (ftp ... 비동기로 수행하고 싶지만 지금은 성공하지 못했습니다.) "바인딩"속성 (알림 및 알림 실행 클래스)이 변경된 것 같습니다. 상태이지만 활동 표시는 나타나지 않습니다.

바인딩 문제인지, 레이아웃 문제인지, 그 밖의 것들은 무엇인지 모르겠습니다. 누구든지 나를 도울 수 있습니까?

페이지

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)); 
       } 
      } 
     } 
    } 
} 

답변

0

안녕하세요이 (안드로이드 버전) 할 수있는 진행 대화 상자를 사용하고 있습니다. 그리고 난 그냥 사용하는 로딩 화면 표시 할 때

using System; 
using Xamarin.Forms; 
#if __ANDROID__ 
using Android.App; 
#endif 

namespace SEEForgeX.Helpers 
{ 
    public class BaseContentPage : ContentPage 
    { 
     #region PRIVATE VARIABLES 
#if __ANDROID__ 
     ProgressDialog p = null; 
#endif 
     #endregion 

     #region PROPERTIES 
     public bool IsShowing { get; set; } 
     public bool LoadingViewFlag { 
      get { 
       return (bool)GetValue (LoadingProperty); 
      } 
      set { 
       SetValue (LoadingProperty, value); 

#if __ANDROID__ 
       if (value == true) 
       { 
        p = new ProgressDialog(Forms.Context); 
        p.SetMessage("Loading..."); 
        p.SetCancelable(false); 
        p.Show(); 
        IsShowing = true; 
       } 
       else 
       { 
        if (p != null) 
        { 
         p.Dismiss(); 
         p = null; 
         IsShowing = false; 
        } 
       } 
#endif 
      } 
     } 

     public static readonly BindableProperty LoadingProperty = 
      BindableProperty.Create ((BaseContentPage w) => w.LoadingViewFlag, false); 
     #endregion 

     public BaseContentPage() 
     { 
     } 
    } 
} 

전나무 아이폰 OS 내가 정의 렌더러를 사용하고 있습니다 : 내 클래스 (BaseContentPage)를 사용하여 오전 ContentPage을 사용하는 대신에, LoadingViewFlag =이 참/거짓을. 네가 필요하면 알려줘.