I have an AppBarButton
which displays a MenuFlyout
when clicked. And that button is in a CommandBar
.
However, after it is collapsed to the MoreButton
due to the overflow, the AppBarButton's Flyout becomes hard to click. This is because the MoreButton
creates a Flyout
and the second click on the AppBarButton
hides both Flyout
.
So how can I resolve this problem?
Preferably, I want the AppBarButton
to be converted to a MenuFlyoutSubItem
, but I don't know how to do that.
Another problem about the overflow is that, although I have set the CornerRadius
of the MoreButton
to be 20 in its style, it is still a rectangle indeed. What is wrong?
<Button
x:Name="MoreButton"
Grid.Column="1"
MinHeight="{ThemeResource AppBarThemeCompactHeight}"
Padding="{ThemeResource CommandBarMoreButtonMargin}"
VerticalAlignment="Top"
Control.IsTemplateKeyTipTarget="True"
CornerRadius="20"
Foreground="{TemplateBinding Foreground}"
IsAccessKeyScope="True"
Style="{StaticResource EllipsisButton}"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CommandBarTemplateSettings.EffectiveOverflowButtonVisibility}">
<FontIcon
x:Name="EllipsisIcon"
Height="{ThemeResource AppBarExpandButtonCircleDiameter}"
VerticalAlignment="Center"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="20"
Glyph="" />
</Button>
This is Flyout
light dismiss behavior and it's by design, for more please refer this document. For your requirement please avoid put the MenuFlyout
in to MoreButton's flyout. I think you could place all the items in the SecondaryCommands
and use AppBarSeparator
to split into different areas.
<CommandBar Background="Transparent" IsOpen="False" DefaultLabelPosition="Right">
<AppBarButton Icon="Add" Label="Add"/>
<AppBarButton Icon="ReShare" Label="Share"/>
<AppBarButton Icon="Edit" Label="Edit"/>
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Setting" Label="Settings">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="S" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarButton Icon="Add" Label="Button 1">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="N" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarButton Icon="Delete" Label="Button 2">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Key="Delete" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarSeparator />
<AppBarButton Icon="FontDecrease" Label="Button 3">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="Subtract" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarButton Icon="FontIncrease" Label="Button 4">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="Add" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
</CommandBar.SecondaryCommands>
</CommandBar>
Another problem about the overflow is that, although I have set the CornerRadius of the MoreButton to be 20 in its style, it is still a rectangle indeed. What is wrong
I used the following style and the CornerRadius
works well
<Style TargetType="CommandBar">
.....
<Button x:Name="MoreButton"
Background="Red"
CornerRadius="20"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource EllipsisButtonRevealStyle}"
Padding="{ThemeResource CommandBarMoreButtonMargin}"
MinHeight="{ThemeResource AppBarThemeCompactHeight}"
VerticalAlignment="Top"
Grid.Column="1"
Control.IsTemplateKeyTipTarget="True"
IsAccessKeyScope="True"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CommandBarTemplateSettings.EffectiveOverflowButtonVisibility}">
<FontIcon x:Name="EllipsisIcon"
VerticalAlignment="Center"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="20"
Glyph=""
Height="{ThemeResource AppBarExpandButtonCircleDiameter}" />
</Button>
.....
</Style>
Update
<Border Grid.Column="1" CornerRadius="20">
<Button
x:Name="MoreButton"
MinHeight="{ThemeResource AppBarThemeCompactHeight}"
Padding="{ThemeResource CommandBarMoreButtonMargin}"
VerticalAlignment="Top"
Control.IsTemplateKeyTipTarget="True"
Foreground="{TemplateBinding Foreground}"
IsAccessKeyScope="True"
Style="{StaticResource EllipsisButton}"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CommandBarTemplateSettings.EffectiveOverflowButtonVisibility}"
>
<FontIcon
x:Name="EllipsisIcon"
Height="{ThemeResource AppBarExpandButtonCircleDiameter}"
VerticalAlignment="Center"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="20"
Glyph=""
/>
</Button>
</Border>