简体   繁体   English

CommandBarFlyout (WinUi 2.7) 使用辅助命令突出显示不当行为

[英]CommandBarFlyout (WinUi 2.7) Highlighting Misbehavior Using Secondary Commands

I have a CommandBarFlyout implemented with Secondary Commands within Secondary Commands like so:我有一个 CommandBarFlyout 在辅助命令中使用辅助命令实现,如下所示:

<Grid Margin="0,50">
                    <Grid.Resources>
                        <muxc:CommandBarFlyout Placement="Bottom" x:Name="CommandBarFlyout">
                            <AppBarButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleSimpleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}" />
                            </AppBarButton>
                            <AppBarButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleSimpleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}" />
                            </AppBarButton>
                            <AppBarButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleSimpleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}" />
                            </AppBarButton>
                            <AppBarButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleSimpleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}" />
                            </AppBarButton>

                            <AppBarToggleButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}"/>
                            </AppBarToggleButton>
                            <AppBarToggleButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}" />
                            </AppBarToggleButton>
                            <AppBarToggleButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}" />
                            </AppBarToggleButton>
                            <AppBarToggleButton ToolTipService.ToolTip="{Binding CommandBarButtonText}" Visibility="{Binding ToggleVisibility}">
                                <FontIcon Style="{StaticResource FontIconAppBar}"/>
                            </AppBarToggleButton>

                            <muxc:CommandBarFlyout.SecondaryCommands>
                                <AppBarButton x:Name="CascadingAppBarButton" Visibility="Collapsed" Label="{Binding CommandBarButtonText}">
                                    <AppBarButton.Flyout>
                                        <CommandBarFlyout Placement="Right">
                                            <CommandBarFlyout.SecondaryCommands>
                                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                            </CommandBarFlyout.SecondaryCommands>
                                        </CommandBarFlyout>
                                    </AppBarButton.Flyout>
                                </AppBarButton>
                                <AppBarButton  Label="{Binding CommandBarButtonText}" />
                                <AppBarButton  Label="{Binding CommandBarButtonText}" />
                                <AppBarSeparator />
                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                            </muxc:CommandBarFlyout.SecondaryCommands>
                        </muxc:CommandBarFlyout>
                    </Grid.Resources>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="2*" />
                        </Grid.ColumnDefinitions>
                        <StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Button x:Name="CommandButton"
                                Content="{Binding ButtonText}"
                                Click="ButtonClick"
                                ContextRequested="ButtonContextRequested" />
                        </StackPanel>
                        <StackPanel Grid.Column="1" HorizontalAlignment="Center">
                            <CheckBox x:Name="ToggleCheckbox" Content="{Binding ToggleButtonCheckBoxTitle}" Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked" IsChecked="False" />
                            <CheckBox Content="{Binding CascadingMenuCheckBoxTitle}" Checked="CascadingMenu_Checked" Unchecked="CascadingMenu_Unchecked" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </StackPanel>
        </Grid>

I tried testing this code adding specifically the secondary commands within the XAML Controls Gallery code, and reproduced the same behavior I observed in my implementation.我尝试测试此代码,特别是在 XAML 控件库代码中添加辅助命令,并重现了我在实施中观察到的相同行为。

In design the expected behavior is the highlight should persist在设计中预期的行为是亮点应该坚持在此处输入图像描述

In development the highlighting is lost after 2 seconds, and stays like this:在开发过程中,突出显示会在 2 秒后消失,并保持如下状态: 在此处输入图像描述

XAML Controls Gallery has the following example: XAML 控件库有以下示例:

在此处输入图像描述

So the highlighting works as expected for Primary Commands and Secondary Commands, but incorrectly in the implementation above.因此,主要命令和次要命令的突出显示按预期工作,但在上面的实现中不正确。

Question is: Is this really a bug or incorrect implementation due to nesting of Secondary Commands?问题是:由于二级命令的嵌套,这真的是一个错误或不正确的实现吗?

That's an interesting behavior.这是一个有趣的行为。 I could reproduce this behavior on my side using your code.我可以使用您的代码在我这边重现此行为。 Then I tried the code from the official document - Create a command bar flyout and added the CascadingAppBarButton from your code to the sample code.然后我尝试了官方文档中的代码 - 创建一个命令栏弹出窗口并将代码中的CascadingAppBarButton添加到示例代码中。 The result shows that the highlighting works as expected.结果显示突出显示按预期工作。

After comparing the code, I found a simple change might help to correct this behavior.比较代码后,我发现一个简单的更改可能有助于纠正此行为。 You might need to set the Icon property of the AppBarButton .您可能需要设置AppBarButtonIcon属性。

Here is the code I use that works correctly.这是我使用的可以正常工作的代码。 As you could see, I just set the Icon property for the last AppBarButton .如您所见,我只是为最后一个AppBarButton设置了Icon属性。

  <muxc:CommandBarFlyout.SecondaryCommands>
                <AppBarButton x:Name="CascadingAppBarButton" Visibility="Visible" Label="{Binding CommandBarButtonText}">
                    <AppBarButton.Flyout>
                        <CommandBarFlyout Placement="Right">
                            <CommandBarFlyout.SecondaryCommands>
                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                            </CommandBarFlyout.SecondaryCommands>
                        </CommandBarFlyout>
                    </AppBarButton.Flyout>
                </AppBarButton>
                <AppBarButton  Label="{Binding CommandBarButtonText}" />
                <AppBarButton  Label="{Binding CommandBarButtonText}" />
                <AppBarSeparator />
                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" />
                <AppBarToggleButton  Label="{Binding CommandBarToggleButtonText}" Icon="Delete" />
            </muxc:CommandBarFlyout.SecondaryCommands>
        </muxc:CommandBarFlyout>

It's just a workaround for this behavior.这只是此行为的解决方法。 If you want to dig further into this behavior.如果您想进一步研究这种行为。 I'd suggest you open an issue and report this in the WinUI-GitHub我建议你打开一个问题并在WinUI-GitHub中报告这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM