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 :

MVVM Bind Command on Ribbon Button


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Octobre 2007
    Messages
    84
    Détails du profil
    Informations forums :
    Inscription : Octobre 2007
    Messages : 84
    Par défaut MVVM Bind Command on Ribbon Button
    Bonjour,

    Est-il possible de binder un bouton d'un Ribbon présent dans une fenêtre WPF maitre avec une commande défini dans le ViewModel lié à un usercontrol.

    Si je créé un bouton dans mon usercontrol que je lie à la commande définie dans mon ViewModel, et que j'inclue le usercontrol dans ma fenêtre maitre, la commande s'exécute correctement.

    Par contre impossible de lié correctement un bouton du ribbon à sa commande :

    User Control
    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
     
    <UserControl x:Class="BookStoreWPF3.View.BookView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:viewmodel="clr-namespace:BookStoreWPF3.ViewModel"
                 mc:Ignorable="d" xmlns:my="clr-namespace:BookStoreWPF3.Model" Loaded="UserControl_Loaded" d:DesignHeight="422" d:DesignWidth="585">
        <UserControl.Resources>
            <DataTemplate DataType="{x:Type viewmodel:BookViewModel}" />
        </UserControl.Resources>
        <Grid>
            <Button Content="Delete" Command="{Binding DeleteCommand}" />
        </Grid>
    </UserControl>
    Fenêtre maitre
    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
    <ribbon:RibbonWindow x:Class="BookStoreWPF3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
            xmlns:view="clr-namespace:BookStoreWPF3.View"
            xmlns:viewmodel="clr-namespace:BookStoreWPF3.ViewModel"
            Title="MainWindow"
    		x:Name="RibbonWindow"
    		Width="640" Height="480">
    
    	<Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <ribbon:Ribbon x:Name="Ribbon">
                <ribbon:Ribbon.ApplicationMenu>
                    <ribbon:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png">
                        <ribbon:RibbonApplicationMenuItem Header="Close"
                                                          x:Name="CloseMenuItem"
                                                          ImageSource="Images\LargeIcon.png" Click="CloseMenuItem_Click" />
                    </ribbon:RibbonApplicationMenu>
                </ribbon:Ribbon.ApplicationMenu>
                <ribbon:RibbonTab x:Name="BookTab" 
                                  Header="Book">
                    <ribbon:RibbonGroup x:Name="BookGroup1" 
                                        Header="Actions">
                        <ribbon:RibbonButton x:Name="DeleteButton"
                                             LargeImageSource="Images\LargeIcon.png"
                                             Label="Delete"
                                             Command="{Binding DeleteCommand}" />
                    </ribbon:RibbonGroup>
                    
                </ribbon:RibbonTab>
            </ribbon:Ribbon>
            <view:BookView Grid.Row="1" HorizontalAlignment="Left" Margin="12,6,0,0" x:Name="bookView" VerticalAlignment="Top" />
        </Grid>
    </ribbon:RibbonWindow>
    Merci de votre aide.

  2. #2
    Membre émérite Avatar de jmix90
    Homme Profil pro
    Consultant .Net
    Inscrit en
    Juillet 2007
    Messages
    576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Paris (Île de France)

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

    Informations forums :
    Inscription : Juillet 2007
    Messages : 576
    Par défaut
    Peut être que cela peut t'aider : http://blog.lexique-du-net.com/index...-Office-Ribbon

Discussions similaires

  1. [MVVM][.net3.5] InputBinding, Binding Command et CommandParameter
    Par Monkey56 dans le forum Windows Presentation Foundation
    Réponses: 10
    Dernier message: 21/06/2011, 18h09
  2. MVVM - Binding Command / Event
    Par Pooch dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 06/01/2011, 17h35
  3. [MVVM] Les commandes de la souris
    Par Robin56 dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 01/07/2009, 15h15
  4. [MVVM] Plusieurs Commands pour un seul element
    Par Krustig dans le forum Windows Presentation Foundation
    Réponses: 8
    Dernier message: 22/05/2009, 19h35
  5. [WPF - Blend] Binding lié à un click button
    Par OS_trimble dans le forum Windows Presentation Foundation
    Réponses: 6
    Dernier message: 06/12/2007, 14h28

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