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.

juFo
  • 17,849
  • 10
  • 105
  • 142
  • 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. – Charleh Oct 31 '13 at 22:58

1 Answers1

2

Thanks @Charleh for the hint (I really had no clue about it) I found a good answer here: https://stackoverflow.com/a/18980558/187650

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>
Community
  • 1
  • 1
juFo
  • 17,849
  • 10
  • 105
  • 142