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:
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 :
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:
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
<!--<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.
Partager