AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.09k stars 2.26k forks source link

Setting MenuItem Header to - makes it separator and does not display text #1902

Open wieslawsoltes opened 6 years ago

wieslawsoltes commented 6 years ago

Setting MenuItem Header to - makes it separator and does not display text.

repro:

<MenuItem Header="-"/>

1

2

style used:

<Style Selector="MenuItem">
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="FontSize" Value="12"/>
</Style>

version: 0.6.2-build6248-beta

jmacato commented 6 years ago

@wieslawsoltes it's a feature added in https://github.com/AvaloniaUI/Avalonia/pull/1891 :smile:

wieslawsoltes commented 6 years ago

So how can I force not to make menu item a separator?

grokys commented 6 years ago

Why do you need a menu item with a header of "-"?

wieslawsoltes commented 6 years ago

I use it for remove button like this:

        <Menu Grid.Row="2" HorizontalAlignment="Right" IsVisible="{Binding !!$self.DataContext}">
            <MenuItem Header="apply" Command="{Binding $parent[Window].DataContext.OnApplyStyle}" CommandParameter="{Binding Selected}" IsVisible="{Binding !!Selected}"/>
            <MenuItem Header="+" Command="{Binding $parent[Window].DataContext.OnAddStyle}" CommandParameter="{Binding}"/>
            <MenuItem Header="-" Command="{Binding $parent[Window].DataContext.OnRemoveStyle}" CommandParameter="{Binding Selected}" IsVisible="{Binding !!Selected}"/>
        </Menu>

https://github.com/wieslawsoltes/Core2D/blob/2e508238ac895f8676a419aac7c2cbe0a7793316/src/Core2D.UI.Avalonia/Views/Containers/StylesControl.xaml#L34-L38

grokys commented 6 years ago

I should have known that someone would be using a menu item with just a "-". Sigh. I wonder how you do this in winforms?

danwalmsley commented 6 years ago

maybe we can use something less likely for separators, like empty string or ":separator" or something.

grokys commented 6 years ago

No, someone will want to use whatever string as a menu item. I actually think "-" is the best string to use as it's use as a separator is widespread, we're just following patterns used in other frameworks. Would suggesting that an em-dash or another char be used instead in the unusual case of wanting a dash as a menu be acceptable do you think?

wieslawsoltes commented 6 years ago

I will use Header="X" for my menu items as its seems like - for separator is convenient to use.

Anyway it would be good to have some mechanism to disable this behavior.

grokys commented 6 years ago

You could use <MenuItem Header="&#727;"/>

Anyway it would be good to have some mechanism to disable this behavior.

Yes, I am looking to see how you do this in WinForms.

robloo commented 2 years ago

Needs a new MenuSeparator similar to UWP:

https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.menuflyoutseparator?view=winrt-22000

maxkatz6 commented 2 years ago

@robloo we have a Separator. It basically works exactly like MenuSeparator in UWP. There are styles for "MenuItem > Separator" selector to make it look right.

"-" support was specifically added before to simplify some use cases https://github.com/AvaloniaUI/Avalonia/pull/1891. But broke another rare scenario.