fluentribbon / Fluent.Ribbon

WPF Ribbon control like in Office
http://fluentribbon.github.io
MIT License
2.48k stars 515 forks source link

DropDownButton.ItemTemplate can't fill the drop-down box #1150

Closed Waiwai-Zhang closed 9 months ago

Waiwai-Zhang commented 11 months ago

As the question, I read template of DropDownButton, but can not find the problem, I think for a long time but can not find a solution. In the blank space of the drop-down box, clicking didn't respond, and I wanted it to. Help me please. The code is as follows.

<fr:DropDownButton Header="Remove" Icon="{StaticResource xxx}" ItemsSource="{Binding xxx}">
    <fr:DropDownButton.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding xxx}"/>
        </DataTemplate>
    </fr:DropDownButton.ItemTemplate>
</fr:DropDownButton>

Environment

Waiwai-Zhang commented 11 months ago

This is a screenshot of the interface, click on the left blank space there is no response. image

batzen commented 11 months ago

By "no response" you mean the dropdown doesn't close? If that's the case i can't reproduce your issue in the showcase application. Could you attach a small repro project then?

Waiwai-Zhang commented 10 months ago

I'm sorry I didn't describe it clearly. I'm using MVVM pattern, and use the Microsoft Xaml. Behaviors. The Wpf package help me binding orders. The complete code looks something like this.

`

` So what I want to do is, when I click on item I get some response, but if I click on the empty space, I don't get any response, I have to click on the text, which means that the blank space for item is occupied, but I don't know how to remove that. ![image](https://github.com/fluentribbon/Fluent.Ribbon/assets/114559580/3570fcfa-0d08-4ca2-90b2-e3c0ab2b6ec5)
batzen commented 10 months ago

That's because you are setting the trigger on the textblock, which means it only triggers on the textblock but not it's parent element (MenuItem).

What you have to do is to create an item container style and use that instead of an itemtemplate.

Waiwai-Zhang commented 10 months ago

I feel your answer very much and it helps me a lot. From what I looked up, the only way to set events in style is through EventSetter, which doesn't support MVVM, and no solution was found in the forums. Do you have any suggestions?

batzen commented 9 months ago

When you provide the container style you can simply also change it's template ;-) Or if you just want to react to a click you could bind a command from your viewmodel to the menuitem. That's most likely the best solution for MVVM.

Waiwai-Zhang commented 9 months ago

Yes, I have rewritten the template of menuitem. Thank you for your help!