IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Phone .NET Discussion :

Gestion de la gestuelle sur les éléments d'une ListBox


Sujet :

Windows Phone .NET

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2014
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Gestion de la gestuelle sur les éléments d'une ListBox
    Bonjour,
    Je cherche un moyen de gérer des évènements sur un élément d’une ListBox construite par Binding sur une ObservableCollection<>. Je programme sur Windows Phone 8.0 en C#.

    J’aimerais que ma ListBox réagisse comme une liste sur iOS : que les lignes réagissent à un swipe (« swipe to delete ») et pouvoir les réordonner.

    Ce que j’aimerais donc c’est savoir comment faire réagir cet élément à un mouvement horizontal (soit pour faire glisser l'item, soit pour faire glisser un StackPanel contenu dans cet item), comment animer cet élément (pour par exemple le faire revenir à sa place quand je commence à déplacer un autre élément de la liste). Sur iOS cela correspondrait à une SWTableViewCell, présentée ici : https://github.com/CEWendel/SWTableViewCell

    Nom : 687474703a2f2f692e696d6775722e636f6d2f7174366149537a2e676966.gif
Affichages : 82
Taille : 540,9 Ko

    Dans un second temps j’aimerai aussi pouvoir réorganiser ma ListBox en faisant glisser verticalement les éléments pour les mettre dans l’ordre souhaité.

    Afin de faire cela j’ai fait un petit code d’exemple qui ne sert à rien mais qui permet de partir de quelque chose.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    <phone:PhoneApplicationPage
        x:Class="PhoneApp1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        mc:Ignorable="d"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        shell:SystemTray.IsVisible="True">
     
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
     
     
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock Text="APP NAME" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
                <TextBlock Text="Page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
     
            <Grid x:Name="ContentPanel" Grid.Row="1">
                <StackPanel>
                    <ListBox x:Name="MainPageList" ItemsSource="{Binding ListBehind}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel Orientation="Horizontal" Background="#7F7F7F7F" Width="480">
                                        <Rectangle Height="40" Width="40" Fill="{Binding RectangleColor}" Stroke="Transparent" StrokeThickness="11"/>
                                        <TextBlock Text="{Binding Text}" VerticalAlignment="Center"/>
                                    </StackPanel>
                                    <Button Content="Clic-me !"/> <!-- Le bouton caché que je lierai par la suite à un évènement -->
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>
            </Grid>
     
        </Grid>
    </phone:PhoneApplicationPage>

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Windows;
    using Microsoft.Phone.Controls;
    using PhoneApp1.Resources;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Collections.ObjectModel;
    using System.Windows.Media;
     
    namespace PhoneApp1
    {
        public class Element : INotifyPropertyChanged
        {
            private string _RectangleColor;
            private string _Text;
     
            public string RectangleColor
            {
                get { return _RectangleColor; }
                set { NotifyPropertyChanged(ref _RectangleColor, value); }
            }
     
            public string Text
            {
                get { return _Text; }
                set { NotifyPropertyChanged(ref _Text, value); }
            }
     
    	// fonctions pour le Binding qui seront utiles une fois que je saurais faire ce que je cherche à faire
            public event PropertyChangedEventHandler PropertyChanged;
            public void NotifyPropertyChanged(string PropertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
            private bool NotifyPropertyChanged<T>(ref T var, T value, [CallerMemberName] string PropertyName = null)
            {
                if (object.Equals(var, value))
                    return false;
                var = value;
                NotifyPropertyChanged(PropertyName);
                return true;
            }
        }
     
        public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged
        {
            private ObservableCollection<Element> _ListBehind;
     
            public MainPage()
            {
                InitializeComponent();
     
                _ListBehind = new ObservableCollection<Element>();
                _ListBehind.Add(new Element { RectangleColor = "#FFFF0000", Text = "Red" });
                _ListBehind.Add(new Element { RectangleColor = "#FF00FF00", Text = "Green" });
                _ListBehind.Add(new Element { RectangleColor = "#FF0000FF", Text = "Blue" });
                _ListBehind.Add(new Element { RectangleColor = "Aqua", Text = "Aqua" });
                _ListBehind.Add(new Element { RectangleColor = "Orange", Text = "Orange" });
                _ListBehind.Add(new Element { RectangleColor = "Gold", Text = "Gold" });
     
                DataContext = this;
            }
     
            public ObservableCollection<Element> ListBehind
            {
                get { return _ListBehind; }
                set { NotifyPropertyChanged(ref _ListBehind, value); }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            public void NotifyPropertyChanged(string PropertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
            private bool NotifyPropertyChanged<T>(ref T var, T value, [CallerMemberName] string PropertyName = null)
            {
                if (object.Equals(var, value))
                    return false;
                var = value;
                NotifyPropertyChanged(PropertyName);
                return true;
            }
        }
    }

  2. #2
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Tu peux utiliser les manipulations : http://technet.microsoft.com/en-us/s...426933(v=vs.96)
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2014
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Je suis désolé mais ton lien ne renvoie vers rien...

Discussions similaires

  1. Evenements sur les éléments d'une ComboBox
    Par j07nathan dans le forum VB.NET
    Réponses: 2
    Dernier message: 08/08/2009, 18h06
  2. Pointeur sur les éléments d'une structure
    Par Marley_T dans le forum C
    Réponses: 16
    Dernier message: 05/05/2008, 23h31
  3. Réponses: 2
    Dernier message: 12/02/2008, 10h51
  4. Travail sur les éléments d'une matrice.
    Par Jefeh dans le forum MATLAB
    Réponses: 6
    Dernier message: 12/11/2007, 15h10
  5. Réponses: 1
    Dernier message: 09/05/2007, 15h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo