Skip to content

Commit

Permalink
Fix splitbutton keyboard accessability. (microsoft#840)
Browse files Browse the repository at this point in the history
* Fix issue where splitbutton flyout content wasn't invokable by keyboard.

* Removed commented code.
  • Loading branch information
StephenLPeters committed Jan 11, 2022
1 parent 7690b07 commit e2e2ead
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 54 deletions.
57 changes: 9 additions & 48 deletions XamlControlsGallery/ControlPages/SplitButtonPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Border x:Name="CurrentColor" Width="{StaticResource SwatchSize}" Height="{StaticResource SwatchSize}" Background="Green" Margin="0" CornerRadius="4,0,0,4"/>
<muxc:SplitButton.Flyout>
<Flyout Placement="Bottom">
<GridView>
<GridView ItemClick="GridView_ItemClick" IsItemClickEnabled="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid MaximumRowsOrColumns="3" Orientation="Horizontal"/>
Expand All @@ -31,55 +31,16 @@
<Setter Property="RadiusX" Value="4"/>
<Setter Property="RadiusY" Value="4"/>
</Style>
<Style TargetType="Button">
<Setter Property="Padding" Value="0"/>
<Setter Property="MinWidth" Value="0"/>
<Setter Property="MinHeight" Value="0"/>
<Setter Property="Margin" Value="6"/>
<Setter Property="CornerRadius" Value="{StaticResource ControlCornerRadius}"/>
</Style>
</GridView.Resources>
<GridView.Items>
<Button Click="ColorButton_Click" AutomationProperties.Name="Red">
<Button.Content>
<Rectangle Fill="Red"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Orange">
<Button.Content>
<Rectangle Fill="Orange"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Yellow">
<Button.Content>
<Rectangle Fill="Yellow"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Green">
<Button.Content>
<Rectangle Fill="Green"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Blue">
<Button.Content>
<Rectangle Fill="Blue"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Indigo">
<Button.Content>
<Rectangle Fill="Indigo"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Violet">
<Button.Content>
<Rectangle Fill="Violet"/>
</Button.Content>
</Button>
<Button Click="ColorButton_Click" AutomationProperties.Name="Gray">
<Button.Content>
<Rectangle Fill="Gray"/>
</Button.Content>
</Button>
<Rectangle Fill="Red"/>
<Rectangle Fill="Orange"/>
<Rectangle Fill="Yellow"/>
<Rectangle Fill="Green"/>
<Rectangle Fill="Blue"/>
<Rectangle Fill="Indigo"/>
<Rectangle Fill="Violet"/>
<Rectangle Fill="Gray"/>
</GridView.Items>
</GridView>

Expand Down
10 changes: 4 additions & 6 deletions XamlControlsGallery/ControlPages/SplitButtonPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;

namespace AppUIBasics.ControlPages
{
Expand All @@ -19,13 +20,10 @@ public SplitButtonPage()
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tempor commodo ullamcorper a lacus.");
}

private void ColorButton_Click(object sender, RoutedEventArgs e)
private void GridView_ItemClick(object sender, ItemClickEventArgs e)
{
// Extract the color of the button that was clicked.
Button clickedColor = (Button)sender;
var rectangle = (Windows.UI.Xaml.Shapes.Rectangle)clickedColor.Content;
var color = ((Windows.UI.Xaml.Media.SolidColorBrush)rectangle.Fill).Color;

var rect = (Rectangle)e.ClickedItem;
var color = ((SolidColorBrush)rect.Fill).Color;
myRichEditBox.Document.Selection.CharacterFormat.ForegroundColor = color;
CurrentColor.Background = new SolidColorBrush(color);

Expand Down

0 comments on commit e2e2ead

Please sign in to comment.