WPF Ribbon Fluent:DropDownButton + Caliburn.Micro event
Asked Answered
A

1

0

I'm trying to use a DropDownButton from the Fluent ribbon control in a WPF application using Caliburn.Micro.

So far, everything is good. I see a list of my Unicorns as GalleryItems in the DropDownButton. The only problem is that I could not get the "ShowUnicorn()" working. When I click on an item from the DropDownButton's list it does nothing. Am I doing something wrong?

This is the code that I use:

<Fluent:DropDownButton Header="Farm"
                   LargeIcon="..\..\Resources\unicorn48.png">
<Fluent:Gallery ItemsSource="{Binding AllUnicorns}">
    <Fluent:Gallery.ItemTemplate>
        <DataTemplate>
            <Fluent:GalleryItem Content="{Binding UnicornFoobar}"
                                cal:Message.Attach="[Event Click] = [Action ShowUnicorn()]" />
        </DataTemplate>
    </Fluent:Gallery.ItemTemplate>
</Fluent:Gallery>

Thanks in advance.

Alive answered 30/10, 2013 at 10:32 Comment(1)
I think it's the old DataTemplate issue - there are a few answers to this one floating around on SO but generally you need to bind cal:Action.TargetWithoutContext to the ViewModel. Basically what's happening is that the DataContext for each row is the actual data item itself (not the VM) and when you click, CM is trying to resolve the method against the data item. You need to tell CM that you want to target the VM with the action and not the data row in the gallery.Brachy
A
2

Thanks @Charleh for the hint (I really had no clue about it) I found a good answer here: https://mcmap.net/q/1680867/-how-to-bind-a-button-on-wpf-grid-to-a-method-on-mvvm-when-i-am-using-caliburn-micro

Also I changed the Fluent:GalleryItem with a Button:

<Fluent:DropDownButton x:Name="aaaa" 
                   Header="Farm"
                   LargeIcon="..\..\Resources\unicorn48.png">
<Fluent:Gallery ItemsSource="{Binding AllUnicorns}">
    <Fluent:Gallery.ItemTemplate>
        <DataTemplate>
            <Button Content="{Binding UnicornFoobar}"
                    cal:Message.Attach="[Event Click] = [Action ShowUnicorn($dataContext)]"
                    cal:Action.TargetWithoutContext="{Binding DataContext, ElementName=aaaa}" />
        </DataTemplate>
    </Fluent:Gallery.ItemTemplate>
</Fluent:Gallery>
Alive answered 1/11, 2013 at 13:21 Comment(1)
I feel omnipresent today!Brachy

© 2022 - 2024 — McMap. All rights reserved.