2016-08-05 3 views
0

Ich arbeite an Android-Anwendung, und ich möchte Renderer in Xamarin Formen zum Swipe die Elemente von ListView erstellen. Aber ich weiß nicht, wie Swipe funktioniert. Wenn eine Stelle eine Idee haben, bitte hier mit mir teilen mein Code: -Swipe-Liste Artikel in Xamarin Forms anzeigen (Android)

public class NativeCell : ViewCell 
    { 
    } 

hier ist der Code von Renderer: -

[assembly: ExportRenderer(typeof(ViewCell), typeof(CustomViewCell))] namespace SwipeListItemRenderer.Droid.CustomControls { 
    public class CustomViewCell : ViewCellRenderer 
    { 
     protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context) 
     { 
      var cell= base.GetCellCore(item, convertView, parent, context); 
      cell.GenericMotion += Cell_GenericMotion; 

      return cell; 
     } 

     private void Cell_GenericMotion(object sender, GenericMotionEventArgs e) 
     { 

     } 
    } } 

Ich habe den Renderer für ViewCell von Listview bauen, möchte ich Swipe Artikel links, dass nach rechts, die ich will Geste Ereignis ausgelöst: -

private void Cell_GenericMotion(object sender, GenericMotionEventArgs e) 
     { 

     } 
+0

Mögliches Duplikat von [SwipeListView in Xamarin Form] (http://stackoverflow.com/questions/38767659/swipelistview-in-xamarin-form) –

+0

Bitte aktualisieren Sie Ihre bestehende Frage, wenn Sie mehr hinzufügen müssen. –

Antwort

0

Es ist möglich machen Swipe PanGesture verwenden.

Ich habe swipecomponent mit Swipe-Ereignis mit Pangesture in PCL-Projekt erstellen.

Attach PanGesture Ereignis

PanGestureRecognizer panGesture = new PanGestureRecognizer(); 
panGesture.PanUpdated += PanGesture_PanUpdated; 
GestureRecognizers.Add(panGesture); 

PanGesture_PanUpdated

private void PanGesture_PanUpdated(object sender, PanUpdatedEventArgs e) 
{ 
    try 
    { 
     switch (e.StatusType) 
     { 
      case GestureStatus.Running: 
       { 
        _gestureX = e.TotalX; 
        _gestureY = e.TotalY; 
       } 
       break; 
      case GestureStatus.Completed: 
       { 
        IsSwipe = true; 
        //Debug.WriteLine("{0} {1}", _gestureX, _gestureY); 
        if (Math.Abs(_gestureX) > Math.Abs(_gestureY)) 
        { 
         if (_gestureX > 0) 
         { 
          OnSwipeRight(null); 
         } 
         else 
         { 
          OnSwipeLeft(null); 
         } 
        } 
        else 
        { 
         if (_gestureY > 0) 
         { 
          OnSwipeDown(null); 
         } 
         else 
         { 
          OnSwipeUP(null); 
         } 
        } 
       } 
       break; 
     } 
    } 
    catch (Exception ex) 
    { 
    } 
} 

benutzerdefinierten Event

public event EventHandler SwipeUP; 
protected void OnSwipeUP(EventArgs e) 
{ 
    if (SwipeUP != null) 
     SwipeUP(this, e); 
} 

public event EventHandler SwipeDown; 
protected void OnSwipeDown(EventArgs e) 
{ 
    if (SwipeDown != null) 
     SwipeDown(this, e); 
} 

public event EventHandler SwipeRight; 
protected void OnSwipeRight(EventArgs e) 
{ 
    if (SwipeRight != null) 
     SwipeRight(this, e); 
} 

public event EventHandler SwipeLeft; 
protected void OnSwipeLeft(EventArgs e) 
{ 
    if (SwipeLeft != null) 
     SwipeLeft(this, e); 
} 

Swipe Probe mit souceCode in Github https://github.com/act70255/ListViewSwipeGesture Btw Bitte aktualisieren Xamarin auf 2,3

hinzufügen