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.