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 Presentation Foundation Discussion :

Raccourcis Clavier Expander WPF C# [Débutant(e)]


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 1
    Par défaut Raccourcis Clavier Expander WPF C#
    Bonjour tout le monde
    voila je me présente au début je suis une nouvelle débutante en développement environnement technologie Microsoft: je viens de créer une petite application point de vente qui me consiste avoir des raccourcis clavier pour chaque contrôle (WPF/C#): mon contrôle c'est le expander, j'ai essayer d'ajouter sur son header un bouton ayant un évènement de clique quand il se déclencha il ouvre l'expander
    WPF:
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <expander.header>
     <Button  x:Name="clikexp" Content="Rechercher par" Click="clikexp_Click" />
    </expander.header>
    C#:
    dans l’évènement de clique "clikexp" je veux mettre:
    si la touche est Enter alors j'ai
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    expander.IsExpanded = true;
    si la touche est Escape alors j'ai
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    expander.IsExpanded = false;
    Merci beaucoup de votre patience, j'attend vos réponses

  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 : 50
    Localisation : Belgique

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

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Par défaut
    Tu peux utiliser les KeyBindings.

    Code xaml : 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
     
    <Window x:Class="WpfApplication2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
     
        </Window.Resources>
        <Window.InputBindings>
            <KeyBinding Command="{Binding OpenExpanderCommand}"
                        Gesture="Return" />
            <KeyBinding Command="{Binding CloseExpanderCommand}"
                        Gesture="Escape" />
        </Window.InputBindings>
        <Border CornerRadius="10" Background="#FFEAEBDD" Margin="20">
            <Expander x:Name="TheExpander">
                <TextBlock FontSize="30" Text="Hello World" />
            </Expander>
     
        </Border>
    </Window>

    Code c# : 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
     
    using GalaSoft.MvvmLight.Command;
     
    namespace WpfApplication2
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow
        {
     
            private RelayCommand _openExpanderCommand;
     
            public RelayCommand OpenExpanderCommand { get { return _openExpanderCommand ?? (_openExpanderCommand = new RelayCommand(() => TheExpander.IsExpanded = true)); }}
     
     
            private RelayCommand _closeExpanderCommand;
     
            public RelayCommand CloseExpanderCommand { get { return _closeExpanderCommand ?? (_closeExpanderCommand = new RelayCommand(() => TheExpander.IsExpanded = false)); } }
     
     
            public MainWindow()
            {
     
     
                this.DataContext = this;
     
                InitializeComponent();
            }
     
        }
     
    }

    Le code n'est pas MVVM (Mais j'utilise RelayCommand de la librairie MVVM Light comme implémentation de ICommand) mais c'est un bon début.

Discussions similaires

  1. [Débutant] [VB.NET] Raccourci clavier WPF
    Par shurikeNzL dans le forum VB.NET
    Réponses: 9
    Dernier message: 12/06/2015, 17h30
  2. Raccourci clavier WPF
    Par Lostincode dans le forum C#
    Réponses: 2
    Dernier message: 02/08/2012, 15h03
  3. [JTable] Raccourci clavier sur une Table
    Par sylvain_2020 dans le forum Composants
    Réponses: 5
    Dernier message: 05/07/2007, 09h01
  4. [BPW]Raccourcis clavier dans une fenêtre enfant
    Par Alcatîz dans le forum Turbo Pascal
    Réponses: 2
    Dernier message: 18/02/2004, 20h07
  5. [] Raccourci clavier pour bouton d'une barre d'outil
    Par Sébastien dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 24/03/2003, 17h02

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