Skip to content

Commit

Permalink
Fix issue with TextCommandBarFlyout not opening when using custom but…
Browse files Browse the repository at this point in the history
…ton (#3022)

* Fix issue with TextCommandBarFlyout not opening when using custom button

* Remove selectionflyout setter

* Fix crash on < RS5
  • Loading branch information
marcelwgn authored Aug 4, 2020
1 parent 34a6bab commit 6265117
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
20 changes: 20 additions & 0 deletions dev/CommandBarFlyout/InteractionTests/TextCommandBarFlyoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,26 @@ public void ValidateUnhandledKeysOnNonTransientFlyoutDoNotCloseFlyout()
}
}

[TestMethod]
public void VerifyTextCommandBarRemainsOpenWithItems()
{
using (var setup = new TestSetupHelper(new[] { "CommandBarFlyout Tests", "Extra CommandBarFlyout Tests" }))
{
Log.Comment("Clear the clipboard.");
FindElement.ById<Button>("ClearClipboardContentsButton").InvokeAndWait();

Log.Comment("Right-click on the text box with additional items.");
FindElement.ByName("TextBoxWithAdditionalItems").Click(PointerButtons.Secondary, 20, 20);

Wait.ForIdle();

Log.Comment("Count the number of open popups.");
FindElement.ById<Button>("CountPopupsButton").InvokeAndWait();

Verify.AreEqual("1", FindElement.ById<Edit>("CustomButtonsOpenCount").Value);
}
}

private void OpenFlyoutOn(string textControlName, bool asTransient)
{
Log.Comment("Opening text control flyout on the {0} in {1} mode.", textControlName, asTransient ? "transient" : "standard");
Expand Down
6 changes: 4 additions & 2 deletions dev/CommandBarFlyout/TestUI/ExtraCommandBarFlyoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<TextBlock Text="Demo controls" Style="{ThemeResource StandardGroupHeader}"/>
<StackPanel Orientation="Horizontal">
<TextBox x:Name="TextBox1" AutomationProperties.AutomationId="TextBox" ContextFlyout="{x:Bind TextCommandBarContextFlyout}"
MinWidth="200" SelectionFlyout="{x:Bind TextCommandBarSelectionFlyout}" />
<RichTextBlock x:Name="RichTextBlock1" AutomationProperties.AutomationId="RichTextBlock" Margin="10" OverflowContentTarget="{x:Bind RichTextBlockOverflow1}" ContextFlyout="{x:Bind TextCommandBarContextFlyout}" SelectionFlyout="{x:Bind TextCommandBarSelectionFlyout}" Width="100" Height="50" HorizontalAlignment="Center">
MinWidth="200" />
<RichTextBlock x:Name="RichTextBlock1" AutomationProperties.AutomationId="RichTextBlock" Margin="10" OverflowContentTarget="{x:Bind RichTextBlockOverflow1}" ContextFlyout="{x:Bind TextCommandBarContextFlyout}" Width="100" Height="50" HorizontalAlignment="Center">
<RichTextBlock.Blocks>
<Paragraph>
<Run>This is a very, very long string that cannot possibly fit within the RichTextBlock's bounds, so it overflows.</Run>
Expand Down Expand Up @@ -58,11 +58,13 @@
</StackPanel>
<TextBlock Text="Actions" Style="{ThemeResource StandardGroupHeader}" Margin="0,24,0,8"/>
<Button AutomationProperties.AutomationId="ClearClipboardContentsButton" Content="Clear clipboard" Click="OnClearClipboardContentsClicked" />
<TextBox x:Name="tb" Loaded="tbloaded" Unloaded="tbunloaded" AutomationProperties.Name="TextBoxWithAdditionalItems"/>

<TextBlock Text="Status" Style="{ThemeResource StandardGroupHeader}" Margin="0,24,0,8"/>
<StackPanel Orientation="Horizontal">
<Button AutomationProperties.AutomationId="CountPopupsButton" Content="Count popups" Click="OnCountPopupsClicked" Margin="0,0,8,0"/>
<TextBox x:Name="PopupCountTextBox" AutomationProperties.AutomationId="PopupCountTextBox" IsReadOnly="True" />
<TextBox x:Name="CustomButtonsOpenCount" AutomationProperties.AutomationId="CustomButtonsOpenCount" IsReadOnly="True" />
</StackPanel>
</StackPanel>
</local:TestPage>
31 changes: 30 additions & 1 deletion dev/CommandBarFlyout/TestUI/ExtraCommandBarFlyoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace MUXControlsTestApp
{
public sealed partial class ExtraCommandBarFlyoutPage : TestPage
{
private int customButtonsFlyoutOpenCount = 0;

public ExtraCommandBarFlyoutPage()
{
this.InitializeComponent();
Expand Down Expand Up @@ -49,7 +51,7 @@ public ExtraCommandBarFlyoutPage()
TextBox1.ContextFlyout = TextCommandBarContextFlyout;
RichTextBlock1.ContextFlyout = TextCommandBarContextFlyout;
}

try
{
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.TextBox", "SelectionFlyout"))
Expand All @@ -76,6 +78,33 @@ private void OnClearClipboardContentsClicked(object sender, object args)
private void OnCountPopupsClicked(object sender, object args)
{
PopupCountTextBox.Text = VisualTreeHelper.GetOpenPopups(Window.Current).Count.ToString();
CustomButtonsOpenCount.Text = customButtonsFlyoutOpenCount.ToString();
}

private void tbloaded(object sender, RoutedEventArgs e)
{
tb.ContextFlyout = new Microsoft.UI.Xaml.Controls.TextCommandBarFlyout();
tb.ContextFlyout.Opening += ContextFlyout_Opening;
tb.ContextFlyout.Closed += ContextFlyout_Closed;
}

private void tbunloaded(object sender, RoutedEventArgs e)
{
tb.ContextFlyout.Opening -= ContextFlyout_Opening;
}

private void ContextFlyout_Opening(object sender, object e)
{
customButtonsFlyoutOpenCount++;
var flyout = (sender as Microsoft.UI.Xaml.Controls.TextCommandBarFlyout);
flyout.PrimaryCommands.Add(new AppBarButton() {
Content = new TextBlock() { Text = "Test" }
});
}

private void ContextFlyout_Closed(object sender, object e)
{
customButtonsFlyoutOpenCount--;
}
}
}
5 changes: 5 additions & 0 deletions dev/CommandBarFlyout/TextCommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ TextCommandBarFlyout::TextCommandBarFlyout()
[this](auto const&, auto const&)
{
UpdateButtons();
}
});

Opened({
[this](auto const&, auto const&)
{
// If there aren't any primary commands and we aren't opening expanded,
// or if there are just no commands at all, then we'll have literally no UI to show.
// We'll just close the flyout in that case - nothing should be opening us
Expand Down

0 comments on commit 6265117

Please sign in to comment.