2016-04-06 16 views
0

Takılması gereken bir PlatformEffect alma konusunda sorun yaşıyorum. Görünüşe göre çözülüyor ama eklenmiyor. o verdiği takdirdePlatformEtect eklenemedi mi?

using System; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.iOS; 

[assembly: ResolutionGroupName ("MyCompany")] 
[assembly: ExportEffect (typeof (EffectTestLib.iOS.MyEffect), "MyEffect")] 
namespace EffectTestLib.iOS { 

    public class MyEffect : PlatformEffect { 

     protected override void OnAttached() { 
      System.Diagnostics.Debug.WriteLine ("Effect Attached"); 
      throw new NotImplementedException(); 
     } 

     protected override void OnDetached() { 
      throw new NotImplementedException(); 
     } 

     protected override void OnElementPropertyChanged (System.ComponentModel.PropertyChangedEventArgs args) { 
      base.OnElementPropertyChanged (args); 
     } 
    } 
} 

Yani, bu çıktı "Etkisi Ekli" ve NotImplementedException atmak GEREKEN: Burada EffectTestLib.iOS adında bir iOS kütüphane projesinde PlatformEffect olduğunu. Bunu doğrulamak için uygulamanın çıkışına PlatformEffect yazıyorum

using Xamarin.Forms; 

namespace EffectTest { 
    public class App : Application { 
     public App() { 
      MainPage = new ContentPage { 
       Content = new StackLayout { 
        VerticalOptions = LayoutOptions.Center, 
        Children = { 
         new Label { 
          XAlign = TextAlignment.Center, 
          Text = "Welcome to Xamarin Forms!" 
         } 
        } 
       } 
      }; 
      var effect = Effect.Resolve ("MyCompany.MyEffect"); 
      System.Diagnostics.Debug.WriteLine ("effect=[{0}]",effect); 
      MainPage.Effects.Add(effect); 
     } 
    } 
} 

Bildirim çözülene:

İşte bu PlatformEffect kullanan uygulama için PCL kodudur. Çözmezse, effect=[Xamarin.Forms.NullEffect]'u görmeliyim.

Uygulamalar iOS platform kodu: Sistemini kullanarak; System.Collections.Generic kullanarak ; System.Linq kullanarak ; Foundation kullanarak ; UIKit kullanarak ; Kütüphanemin yükleniyor emin olmak için new EffectTestLib.iOS.MyEffect(); arıyorum

namespace EffectTest.iOS 
{ 
    [Register ("AppDelegate")] 
    public partial class AppDelegate :  global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
    { 
     public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
     { 
      global::Xamarin.Forms.Forms.Init(); 
      new EffectTestLib.iOS.MyEffect(); 

      LoadApplication (new App()); 

      return base.FinishedLaunching (app, options); 
     } 
    } 
} 

dikkat edin.

Ayrıca, iOS platformu projesi, EffectTestLib.iOS kitaplığına bir başvuru içerir.

2016-04-06 10:17:18.342 EffectTest.iOS[26578:8696061] effect=[EffectTestLib.iOS.MyEffect] 

Yani, PlatformEffect doğru çözümlenir: Uygulamayı çalıştırdığınızda

Yani, bu ne olur. Ancak, "Efekt Eklenmiş" çıktı veya NotImplementedException atmıyor. Ayrıca, MainPage'in bir özelliğini değiştirirseniz, MyEffect.OnPropertyChanged'in hiçbir zaman çağrılmadığını unutmayın.

  1. bir ResolutionGroupName özelliğin eklenmesi OnDetached yöntem
  2. geçersiz kılma OnAttached yöntem
  3. geçersiz kılma PlatformEffect sınıfının
  4. bir alt sınıfı oluşturma: geri https://developer.xamarin.com/guides/xamarin-forms/effects/creating/ değinen

    , benim görünür etki sınıfı.

  5. Etki sınıfına bir ExportEffect özniteliği ekleme.

Ve https://developer.xamarin.com/guides/xamarin-forms/effects/creating/#Consuming_the_Effect_in_C'a geri dönersek, etki Efekt koleksiyonunun sayfalarına eklediğim anlaşılıyor.

Burada yanlış olan ne yapıyorum?

+0

Kaynak kodu: https://github.com/baskren/PlatformEffect_issue – baskren

+0

Saket vereceğim tepkiyi tekrarlanması, PlatformEffects Android'de ancak iOS Sayfa elemanlarında çalışır anlaşılmaktadır.Bunu göstermek için [github örnek projesi] 'ni (https://github.com/baskren/PlatformEffect_issue) güncelledim. – baskren

cevap

0
Ben projenizi görülen ve o iş için onun sonra bu gözlemi düzenleyeceksiniz (Çalışır Views'de çalışmıyor sayfasında, o Gözlem olduğunu, MainPage çağrıda kapmayacak, kodunu değiştirmiş

detaylar). Bu şekilde yapmayı deneyin.

using Xamarin.Forms; 

namespace EffectTest { 
    public class App : Application { 
     public App() { 
      var label = new Label(); 
      label.Effects.Add (Effect.Resolve ("MyCompany.EffectCheck")); 
      MainPage = new RootPage(); 
      var effect = Effect.Resolve ("MyCompany.EffectCheck"); 
      System.Diagnostics.Debug.WriteLine ("effect=[{0}]",effect); 
      //MainPage.Effects.Add(Effect.Resolve ("MyCompany.EffectCheck")); 
     } 

     protected override void OnStart() { 
     } 

     protected override void OnSleep() { 
     } 

     protected override void OnResume() { 
     } 
    } 
} 

using Xamarin.Forms; 

namespace EffectTest 
{ 
    public class RootPage:ContentPage 
    { 
     public RootPage() 
     { 
      Content = new StackLayout() { 
       Children = { 
        new Label() 
       } 
      }; 
// this.Effects.Add(Effect.Resolve ("MyCompany.EffectCheck")); will not work 
        Content.Effects.Add(Effect.Resolve ("MyCompany.EffectCheck")); // it will work; 
     } 
    } 

} 
+1

Buna baktığınız için teşekkür ederiz. PlatformEffects'in Android'deki Sayfa öğelerinde, ancak iOS'ta çalışmadığını görüyoruz. Bunu göstermek için [bu örnek github projesi] 'ni güncelledim (https://github.com/baskren/PlatformEffect_issue). – baskren