2017-07-07 5 views
0

編集: Xamarin.Formsでジェスチャーを実装する方法についての回答は投稿しないでください。Xamarin.Formsの添付プロパティのバインディングに関する問題

添付のプロパティを使用してスワイプジェスチャハンドラをエフェクトとして作成しています(Xamarin guidesで説明)。アプローチの議論をスキップする私は、添付されたプロパティの実装に奇妙な問題があります。

ロングストーリーショート(下のコード) - XAMLの添付プロパティへのバインドは機能しません。。私の静的クラスの​​メソッドはまったく実行されません。私はDebug.WriteLine()の結果がアプリの出力に表示されません。デバッガはそこに設定されたブレークポイントにもヒットしません。 ...CommandPropertyChanged()ハンドラと同じです。

これは、取り扱い性のための私のクラスである:

namespace Core.Effects 
{ 
    public static class Gesture 
    { 
     public static readonly BindableProperty SwipeLeftCommandProperty = 
      BindableProperty.CreateAttached("SwipeLeftCommand", typeof(ICommand), typeof(Gesture), null, propertyChanged: SwipeLeftCommandPropertyChanged); 

     public static readonly BindableProperty SwipeRightCommandProperty = 
      BindableProperty.CreateAttached("SwipeRightCommand", typeof(ICommand), typeof(Gesture), null, propertyChanged: SwipeRightCommandPropertyChanged); 

     public static ICommand GetSwipeLeftCommand(BindableObject view) 
     { 
      Debug.WriteLine("GetSwipeLeftCommand"); 
      return (ICommand) view.GetValue(SwipeLeftCommandProperty); 
     } 

     public static void SetSwipeLeftCommand(BindableObject view, ICommand value) 
     { 
      Debug.WriteLine("SetSwipeLeftCommand"); 
      view.SetValue(SwipeLeftCommandProperty, value); 
     } 

     public static ICommand GetSwipeRightCommand(BindableObject view) 
     { 
      Debug.WriteLine("GetSwipeRightCommand"); 
      return (ICommand) view.GetValue(SwipeRightCommandProperty); 
     } 

     public static void SetSwipeRightCommand(BindableObject view, ICommand value) 
     { 
      Debug.WriteLine("SetSwipeRightCommand"); 
      view.SetValue(SwipeRightCommandProperty, value); 
     } 

     private static void SwipeLeftCommandPropertyChanged(BindableObject bindable, object oldValue, object newValue) 
     { 
      Debug.WriteLine("SwipeLeftCommandPropertyChanged"); 
      // ... 
     } 

     private static void SwipeRightCommandPropertyChanged(BindableObject bindable, object oldValue, object newValue) 
     { 
      Debug.WriteLine("SwipeRightCommandPropertyChanged"); 
      // ... 
     } 

     // ... 
    } 
} 

を、ここで私はXAMLでそれを使用する方法です:

<?xml version="1.0" encoding="UTF-8"?> 

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:effects="clr-namespace:Core.Effects" 
      x:Class="Core.Pages.RequestDetailsPage"> 
    <ContentPage.Content> 
     <StackLayout Spacing="0" 
        Padding="0" 
        VerticalOptions="FillAndExpand" 
        effects:Gesture.SwipeLeftCommand="{Binding NavigateToPreviousRequestCommand}" 
        effects:Gesture.SwipeRightCommand="{Binding NavigateToNextRequestCommand}"> 

私はFreshMvvmで実装私のビューモデル(MVVMで対応するコマンドを持っていますフレームワーク):

namespace Core.PageModels 
{ 
    public class RequestDetailsPageModel : FreshBasePageModel 
    { 
     public IRelayCommand NavigateToNextRequestCommand; 
     public IRelayCommand NavigateToPreviousRequestCommand; 

IRelayCommandがから派生する私のタイプです。 BindingContextはFreshMvvmによって適切に設定されています(このビューの他の場所でうまく機能します)。

何か問題がありますか?

答えて

0

私の間違いは非常にシンプル(どちらか追跡するのはかなり難しい)でした。バインディングは、フィールドではなくプロパティに動作しません:

namespace Core.PageModels 
{ 
    public class RequestDetailsPageModel : FreshBasePageModel 
    { 
     public IRelayCommand NavigateToNextRequestCommand {get; set;} 
     public IRelayCommand NavigateToPreviousRequestCommand {get; set;} 
1
+0

は答えてくれてありがとうしかし、私の質問は、スワイプジェスチャを実装する方法はなかった(私はこれらのソリューションを見てきましたし、彼らは他の部品を実装するために私を助けた)が、* *添付されたプロパティが動作しない理由** 最初のレポに関して - [まだ開いている問題](https://github.com/softlion/XamarinFormsGesture/issues/2)のために機能しません – Marek

+0

レンダラを作成していますか? – Pratik

+0

いいえ、私はしません。質問全体(と私のコメント)を慎重にもう一度読んでください – Marek

関連する問題