Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion components/Ribbon/samples/RibbonCustomSample.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
</Style>
</StackPanel.Resources>

<controls:Ribbon HorizontalAlignment="Stretch">
<controls:Ribbon HorizontalAlignment="Stretch"
OptionsAccessKey="O"
OptionsAccessibleName="Options">

<controls:Ribbon.OptionsFlyout>
<MenuFlyout Placement="BottomEdgeAlignedRight">
<ToggleMenuFlyoutItem Text="Always show toolbar" />
<MenuFlyoutItem Text="Configure" />
</MenuFlyout>
</controls:Ribbon.OptionsFlyout>

<controls:RibbonCollapsibleGroup AccessKey="AB"
CollapsedAccessKey="AA"
Expand Down
72 changes: 72 additions & 0 deletions components/Ribbon/src/Ribbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace CommunityToolkit.WinUI.Controls;
[TemplateVisualState(GroupName = ScrollButtonGroupNameTemplatePart, Name = DecrementButtonStateTemplatePart)]
[TemplateVisualState(GroupName = ScrollButtonGroupNameTemplatePart, Name = IncrementButtonStateTemplatePart)]
[TemplateVisualState(GroupName = ScrollButtonGroupNameTemplatePart, Name = BothButtonsStateTemplatePart)]
[TemplateVisualState(GroupName = OptionsGroupNameTemplatePart, Name = OptionsVisibleStateTemplatePart)]
[TemplateVisualState(GroupName = OptionsGroupNameTemplatePart, Name = OptionsCollapsedStateTemplatePart)]
public sealed partial class Ribbon : Control
{
private const string PanelTemplatePart = "Panel";
Expand All @@ -30,6 +32,9 @@ public sealed partial class Ribbon : Control
private const string DecrementButtonStateTemplatePart = "DecrementButton";
private const string IncrementButtonStateTemplatePart = "IncrementButton";
private const string BothButtonsStateTemplatePart = "BothButtons";
private const string OptionsGroupNameTemplatePart = "OptionsGroup";
private const string OptionsVisibleStateTemplatePart = "OptionsVisible";
private const string OptionsCollapsedStateTemplatePart = "OptionsCollapsed";

private Panel? _panel;
private ScrollViewer? _scrollViewer;
Expand All @@ -55,6 +60,60 @@ public double ScrollStep
set => SetValue(ScrollStepProperty, value);
}

/// <summary>
/// The DP to store the <see cref="OptionsFlyout"/> property value.
/// </summary>
public static readonly DependencyProperty OptionsFlyoutProperty = DependencyProperty.Register(
nameof(OptionsFlyout),
typeof(FlyoutBase),
typeof(Ribbon),
new PropertyMetadata(null, OnOptionsFlyoutPropertyChanged));

/// <summary>
/// The flyout to display when the user clicks on the ribbon options button.
/// </summary>
public FlyoutBase? OptionsFlyout
{
get => (FlyoutBase?)GetValue(OptionsFlyoutProperty);
set => SetValue(OptionsFlyoutProperty, value);
}

/// <summary>
/// The DP to store the <see cref="OptionsAccessibleName"/> property value.
/// </summary>
public static readonly DependencyProperty OptionsAccessibleNameProperty = DependencyProperty.Register(
nameof(OptionsAccessibleName),
typeof(string),
typeof(Ribbon),
new PropertyMetadata(string.Empty));

/// <summary>
/// The accessible name for the options button.
/// </summary>
public string OptionsAccessibleName
{
get => (string)GetValue(OptionsAccessibleNameProperty);
set => SetValue(OptionsAccessibleNameProperty, value);
}

/// <summary>
/// The DP to store the <see cref="OptionsAccessKey"/> property value.
/// </summary>
public static readonly DependencyProperty OptionsAccessKeyProperty = DependencyProperty.Register(
nameof(OptionsAccessKey),
typeof(string),
typeof(Ribbon),
new PropertyMetadata(string.Empty));

/// <summary>
/// The access key to set on the options flyout button.
/// </summary>
public string OptionsAccessKey
{
get => (string)GetValue(OptionsAccessKeyProperty);
set => SetValue(OptionsAccessKeyProperty, value);
}

public Ribbon()
{
DefaultStyleKey = typeof(Ribbon);
Expand Down Expand Up @@ -97,6 +156,8 @@ protected override void OnApplyTemplate()
_scrollViewer.SizeChanged += OnSizeChanged;
UpdateScrollButtonsState();
}

UpdateOptionsFlyoutState();
}

private void OnItemsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
Expand Down Expand Up @@ -198,4 +259,15 @@ private void OnDecrementScrollViewer(object sender, RoutedEventArgs e)

private void OnIncrementScrollViewer(object sender, RoutedEventArgs e)
=> _scrollViewer?.ChangeView(_scrollViewer.HorizontalOffset + ScrollStep, verticalOffset: null, zoomFactor: null);

private static void OnOptionsFlyoutPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ribbon = (Ribbon)d;
ribbon.UpdateOptionsFlyoutState();
}

private void UpdateOptionsFlyoutState() => VisualStateManager.GoToState(
this,
OptionsFlyout != null ? OptionsVisibleStateTemplatePart : OptionsCollapsedStateTemplatePart,
useTransitions: true);
}
25 changes: 25 additions & 0 deletions components/Ribbon/src/RibbonStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<VisualStateManager.VisualStateGroups>
Expand All @@ -380,6 +381,14 @@
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="OptionsGroup">
<VisualState x:Name="OptionsCollapsed" />
<VisualState x:Name="OptionsVisible">
<VisualState.Setters>
<Setter Target="OptionsButton.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<ScrollViewer x:Name="ScrollViewer"
Expand All @@ -397,6 +406,22 @@
Grid.Column="2"
Style="{StaticResource RibbonScrollIncrementButtonStyle}"
Visibility="Collapsed" />

<Button x:Name="OptionsButton"
Grid.Column="3"
Margin="4"
Padding="4"
VerticalAlignment="Bottom"
AccessKey="{TemplateBinding OptionsAccessKey}"
AutomationProperties.Name="{TemplateBinding OptionsAccessibleName}"
Background="Transparent"
BorderBrush="Transparent"
Flyout="{TemplateBinding OptionsFlyout}"
Visibility="Collapsed">
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE70D;" />
</Button>
</Grid>
</ControlTemplate>
</Setter.Value>
Expand Down
Loading