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 :

Probleme avec ribbonButton et commandTarget


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2010
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 2
    Par défaut Probleme avec ribbonButton et commandTarget
    Bonjour a tous,

    Je tente d'affecter une commandTarget sur un ribbonButon mais l'événement canExcecute ne se déclenche pas.

    Voici la fenetre principale:

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    <Window x:Class="WpfApplication1.Window1"
        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:WpfApplication1="clr-namespace:WpfApplication1"
        Title="Window1" Height="300" Width="300">
     
        <Grid>
            <DockPanel>
                <Ribbon:Ribbon FocusManager.IsFocusScope="True" DockPanel.Dock="Top" 
                               Title="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}},Path=Title}">
     
                    <Ribbon:RibbonTab Label="Main">
                        <Ribbon:RibbonTab.Groups>
                            <Ribbon:RibbonGroup>
                                <Ribbon:RibbonGroup.Command>
                                    <Ribbon:RibbonCommand LabelTitle="Checkbook"/>
                                </Ribbon:RibbonGroup.Command>
                                <Ribbon:RibbonButton Command="New" CommandTarget="{Binding ElementName=MyControl}"/>
                                <Ribbon:RibbonButton Command="New"                     CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=WpfApplication1:MyControl}}"/>
                            </Ribbon:RibbonGroup>
                        </Ribbon:RibbonTab.Groups>
                    </Ribbon:RibbonTab>
     
                </Ribbon:Ribbon>
                <!--<Ribbon:RibbonButton Command="New" CommandTarget="{Binding ElementName=MyControl}"/>-->
                <WpfApplication1:MyControl x:Name="MyControl"></WpfApplication1:MyControl>
            </DockPanel>
        </Grid>
    </Window>

    J'ai aussi un Control :

    Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <DockPanel x:Class="WpfApplication1.MyControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="300">
        <DockPanel.CommandBindings>
            <CommandBinding Command="ApplicationCommands.New" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute"/>
        </DockPanel.CommandBindings>
        <Grid>
     
        </Grid>
    </DockPanel>

    et le code cs:
    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
    34
    35
    36
    37
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
     
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MyControl.xaml
        /// </summary>
        public partial class MyControl
        {
            public MyControl()
            {
                InitializeComponent();
            }
     
            private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
            {
     
            }
     
            private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
            {
                e.CanExecute = true;
            }
        }
    }


    Si je de-commente la ligne
    Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
    <!--<Ribbon:RibbonButton Command="New" CommandTarget="{Binding ElementName=MyControl}"/>-->

    sur la main window, ca marche.....

    Comment résoudre mon problème ?? Je voudrais que la commande soit déclenchée sur mon control depuis le ribbon.

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2010
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 2
    Par défaut
    Apres plein d'essais et des heures sur le web; en ajoutant:

    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
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                FocusManager.GetFocusedElement(this);
                InitializeComponent();
                //MainDock.Focus();
                //Focus();
                CutRib.CommandTarget = MyControl;
            }
        }
    }
    la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    CutRib.CommandTarget = MyControl;
    declenche le canExecute.

    Si quelqu'un peux expliquer ce comportement et si c'est la bonne methode ?

    des liens sur le sujet:

    http://blogs.msdn.com/ebooth/archive...31/732609.aspx
    http://social.msdn.microsoft.com/For...8-fcf6cb65263d


Discussions similaires

  1. Probleme avec la copie des surfaces
    Par Black_Daimond dans le forum DirectX
    Réponses: 3
    Dernier message: 09/01/2003, 10h33
  2. Problèmes avec le filtrage des ip
    Par berry dans le forum Réseau
    Réponses: 9
    Dernier message: 30/12/2002, 07h51
  3. probleme avec la touche F10
    Par b.grellee dans le forum Langage
    Réponses: 2
    Dernier message: 15/09/2002, 22h04
  4. Probleme avec fseek
    Par Bjorn dans le forum C
    Réponses: 5
    Dernier message: 04/08/2002, 07h17
  5. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

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