MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

Allow collapsing overflow area of ToolBar

Open krmr opened this issue 2 years ago • 9 comments

Is your feature request related to a problem? Please describe. A ToolBar always contains the area for the overflow, even there is no overflow at all. I am not sure if this is intended behavior or no. For small toolbars I find this rather annoying.

Here a small example, the overflow part is the lighter area to the right of the ‘B’ button: grafik

In the package code itself I can get achieve my expected result by changing ToolBarOverflowButtonVisibilityConverter to return Visibility.Collapsed instead of Visibility.Hidden. But I guess that could cause issues in other use cases.

Describe the solution you'd like The behavior of the overflow area is configurable in XAML.

Describe alternatives you've considered My current workaround is to collapse the overflow grid using an implicit style:

<ToolBar.Resources>
    <Style TargetType="{x:Type Grid}">
        <Setter Property="Visibility" Value="Collapsed" />
    </Style>
</ToolBar.Resources>

This works only as long as there are no other uses of Grid.

Additional context This is based on to 4.5.0.

krmr avatar May 31 '22 10:05 krmr

Can you provide us the xaml code of your example please ?

ElieTaillard avatar May 31 '22 12:05 ElieTaillard

Can you provide us the xaml code of your example please ?

Sure, I have added it to the demo application here: https://github.com/krmr/MaterialDesignInXamlToolkit/blob/toolBarOverflow/MainDemo.Wpf/MenusAndToolBars.xaml (The background color is set to see the extend of the toolbar more easily.)

krmr avatar May 31 '22 14:05 krmr

I think this is a good suggestion. I would propose this be an attached property in a new ToolBarAssist class. I would expect the property to be an enum that follows a similar structure to the ScrollBarVisibility enum (default to Auto, but have members for force visibility).

Keboo avatar May 31 '22 15:05 Keboo

What is the purpose of the OverFlowGrid? I feel like this grid is useless in the template.

ElieTaillard avatar May 31 '22 16:05 ElieTaillard

@Keboo, thanks for your feedback. Actually I had thought along the same lines but was not really sure as the visibilty is set in ToolBarOverflowButtonVisibilityConverter. So I guess it would either have to be an additional parameter for the converter or the converter would have to directly access ToolBarAssist.

@Xaalek regarding the OverFlowGrid I have wondered as well but have not dug any further yet.

krmr avatar Jun 02 '22 06:06 krmr

@krmr I checked the documentation and I saw that we can have overflow items with a button like this: image

https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/toolbar-overview?view=netframeworkdesktop-4.8#toolbars-with-overflow-items

I understand better the usefulness of this grid. Maybe we should just set the overflow area to collapsed when there are no overflow items.

Moreover, currently there is no example in the demo application. I think it would be nice to add an example with this mechanism.

ElieTaillard avatar Jun 03 '22 13:06 ElieTaillard

@Xaalek I think the demo application already has overflow items but it might depend on the window size.

From my point of view we could always collapse the area if there are no overflow items. But that would change the behavior compared to how things are today. For that reason I like the idea of making it configurable as @Keboo proposed.

krmr avatar Jun 03 '22 13:06 krmr

@krmr yes you're right. Thanks for the clarification.

ElieTaillard avatar Jun 04 '22 12:06 ElieTaillard

Can be resolved by adding of Trigger in ControlTemplate of MaterialDesignToolBar

                        <Trigger Property="ToolBar.OverflowMode" Value="Never">
                            <Setter TargetName="OverflowGrid" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="MainPanelBorder" Property="Margin" Value="0,0,0,0" />
                        </Trigger>

shcholeh avatar Jul 06 '23 15:07 shcholeh