Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port microsoft/microsoft-ui-xaml#4587 #630

Merged
merged 1 commit into from
Nov 28, 2023
Merged
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
29 changes: 29 additions & 0 deletions ModernWpf.Controls/RadioMenuItem/RadioMenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ColumnDefinition SharedSizeGroup="{TemplateBinding Visibility, Converter={StaticResource SharedSizeGroupConverter}, ConverterParameter=MenuItemCheckColumnGroup}" Width="Auto" />
<ColumnDefinition SharedSizeGroup="{TemplateBinding Visibility, Converter={StaticResource SharedSizeGroupConverter}, ConverterParameter=MenuItemIconColumnGroup}" Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<ui:FontIconFallback
Expand All @@ -49,32 +50,60 @@
Foreground="{DynamicResource MenuFlyoutSubItemChevron}"
Opacity="0"
Margin="0,0,16,0" />
<Viewbox x:Name="IconRoot"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Width="16"
Height="16"
Margin="0,0,12,0">
<ContentPresenter x:Name="IconContent"
ContentSource="Icon"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Viewbox>
<TextBlock
x:Name="TextBlock"
Grid.Column="2"
Text="{TemplateBinding Header}"
Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<TextBlock x:Name="KeyboardAcceleratorTextBlock"
Grid.Column="3"
Style="{DynamicResource CaptionTextBlockStyle}"
Text="{TemplateBinding InputGestureText}"
Margin="24,0,0,0"
Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"
HorizontalAlignment="Right"
VerticalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Visibility" TargetName="IconRoot" Value="Collapsed" />
</Trigger>
<Trigger Property="InputGestureText" Value="">
<Setter Property="Visibility" TargetName="KeyboardAcceleratorTextBlock" Value="Collapsed" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="CheckGlyph" Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutSubItemBackgroundPointerOver}" />
<Setter TargetName="TextBlock" Property="Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPointerOver}" />
<Setter TargetName="CheckGlyph" Property="Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPointerOver}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutSubItemBackgroundPressed}" />
<Setter TargetName="TextBlock" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPressed}" />
<Setter TargetName="CheckGlyph" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPressed}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPressed}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="TextBlock" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundDisabled}" />
<Setter TargetName="CheckGlyph" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundDisabled}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundDisabled}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
12 changes: 11 additions & 1 deletion ModernWpf/Styles/MenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
Grid.Column="3"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{TemplateBinding InputGestureText}"
Margin="24,4,0,0"
Margin="24,0,0,0"
Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"
HorizontalAlignment="Right"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
Expand All @@ -231,16 +231,22 @@
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutItemBackgroundPointerOver}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPointerOver}" />
<Setter TargetName="CheckGlyph" Property="Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPointerOver}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPointerOver}" />
<Setter TargetName="KeyboardAcceleratorTextBlock" Property="Foreground" Value="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutItemBackgroundPressed}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPressed}" />
<Setter TargetName="CheckGlyph" Property="Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPressed}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundPressed}" />
<Setter TargetName="KeyboardAcceleratorTextBlock" Property="Foreground" Value="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForegroundPressed}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutItemBackgroundDisabled}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundDisabled}" />
<Setter TargetName="CheckGlyph" Property="Foreground" Value="{DynamicResource MenuFlyoutItemForegroundDisabled}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutItemForegroundDisabled}" />
<Setter TargetName="KeyboardAcceleratorTextBlock" Property="Foreground" Value="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForegroundDisabled}" />
</Trigger>
</ControlTemplate.Triggers>
Expand Down Expand Up @@ -359,21 +365,25 @@
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutSubItemBackgroundPointerOver}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPointerOver}" />
<Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemChevronPointerOver}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutSubItemBackgroundPressed}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPressed}" />
<Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemChevronPressed}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsSubmenuOpen" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutSubItemBackgroundSubMenuOpened}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundSubMenuOpened}" />
<Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemChevronSubMenuOpened}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundSubMenuOpened}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="LayoutRoot" Property="Background" Value="{DynamicResource MenuFlyoutSubItemBackgroundDisabled}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundDisabled}" />
<Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource MenuFlyoutSubItemChevronDisabled}" />
<Setter TargetName="IconContent" Property="TextElement.Foreground" Value="{DynamicResource MenuFlyoutSubItemForegroundDisabled}" />
</Trigger>
<!--<Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false" >
<Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding ElementName=SubMenuScrollViewer, Path=VerticalOffset}" />
Expand Down
22 changes: 22 additions & 0 deletions test/ModernWpfTestApp/MenuFlyoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,29 @@
<muxc:SymbolIcon Symbol="Delete" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem">
<ToggleMenuFlyoutItem.Icon>
<muxc:SymbolIcon Symbol="Delete" />
</ToggleMenuFlyoutItem.Icon>
</ToggleMenuFlyoutItem>
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem" InputGestureText="Ctrl+S">
<ToggleMenuFlyoutItem.Icon>
<muxc:SymbolIcon Symbol="Delete" />
</ToggleMenuFlyoutItem.Icon>
</ToggleMenuFlyoutItem>
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem" />
<MenuFlyoutSeparator/>
<RadioMenuFlyoutItem Text="Radio And Has Icon">
<RadioMenuFlyoutItem.Icon>
<muxc:SymbolIcon Symbol="Delete" />
</RadioMenuFlyoutItem.Icon>
</RadioMenuFlyoutItem>
<RadioMenuFlyoutItem Text="Radio with icon and accelerator" InputGestureText="Ctrl+S">
<RadioMenuFlyoutItem.Icon>
<muxc:SymbolIcon Symbol="Delete" />
</RadioMenuFlyoutItem.Icon>
</RadioMenuFlyoutItem>
<RadioMenuFlyoutItem Text="Radio with accelerator" InputGestureText="Ctrl+S"/>
<MenuFlyoutItem Text="Rename"/>
<MenuFlyoutItem Text="Select"/>
</MenuFlyout>
Expand Down
30 changes: 12 additions & 18 deletions test/ModernWpfTestApp/RadioMenuFlyoutItemPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,18 @@
</controls:FlyoutService.Flyout>
</Button>

<Button
Content="I have icons"
Margin="12">
<controls:FlyoutService.Flyout>
<controls:MenuFlyout>
<MenuItem
Header="A Toggle Item"
IsCheckable="True" />
<controls:RadioMenuItem Header="A Radio Item" />
<controls:RadioMenuItem
x:Name="IconRadioMenuFlyoutItem"
Header="Radio And Has Icon" />
<MenuItem
x:Name="IconMenuFlyoutItem"
Header="Just Has Icon" />
</controls:MenuFlyout>
</controls:FlyoutService.Flyout>
</Button>
<ButtonEx Content="I have icons" Margin="12">
<ButtonEx.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem Text="A Toggle Item"/>
<RadioMenuFlyoutItem Text="A Radio Item"/>
<RadioMenuFlyoutItem x:Name="IconRadioMenuFlyoutItem" Text="Radio And Has Icon"/>
<RadioMenuFlyoutItem x:Name="IconRadioMenuFlyoutItem2" Text="Radio with icon and accelerator" InputGestureText="Ctrl+S"/>
<RadioMenuFlyoutItem Text="Radio accelerator" InputGestureText="Ctrl+S"/>
<MenuFlyoutItem x:Name="IconMenuFlyoutItem" Text="Just Has Icon"/>
</MenuFlyout>
</ButtonEx.Flyout>
</ButtonEx>
</StackPanel>
</Border>

Expand Down
1 change: 1 addition & 0 deletions test/ModernWpfTestApp/RadioMenuFlyoutItemPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public RadioMenuFlyoutItemPage()
{
IconMenuFlyoutItem.Icon = new SymbolIcon(Symbol.Calendar);
IconRadioMenuFlyoutItem.Icon = new SymbolIcon(Symbol.Calculator);
IconRadioMenuFlyoutItem2.Icon = new SymbolIcon(Symbol.Calculator);
}

/*if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Grid", "ColumnSpacing"))
Expand Down
53 changes: 52 additions & 1 deletion test/TestAppUtils/Controls/MenuFlyout.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace System.Windows.Controls
using ModernWpf.Controls;

namespace System.Windows.Controls
{
public class MenuFlyout : ModernWpf.Controls.MenuFlyout { }

Expand Down Expand Up @@ -38,6 +40,55 @@ protected override void OnInitialized(EventArgs e)
}
}

public class ToggleMenuFlyoutItem : MenuFlyoutItem
{
static ToggleMenuFlyoutItem()
{
IsCheckableProperty.OverrideMetadata(typeof(ToggleMenuFlyoutItem), new FrameworkPropertyMetadata(true, null, CoerceIsCheckable));
}

private static object CoerceIsCheckable(DependencyObject d, object baseValue)
{
return true;
}
}

public class RadioMenuFlyoutItem : RadioMenuItem
{
#region Text

public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
nameof(Text),
typeof(string),
typeof(RadioMenuFlyoutItem),
new PropertyMetadata(string.Empty, OnTextPropertyChanged));

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private static void OnTextPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
((RadioMenuFlyoutItem)sender).OnTextPropertyChanged(args);
}

private void OnTextPropertyChanged(DependencyPropertyChangedEventArgs args)
{
Header = (string)args.NewValue;
}

#endregion

protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
this.InitializeStyle(DefaultStyleKey);
}
}

public class MenuFlyoutSeparator : Separator
{
protected override void OnInitialized(EventArgs e)
Expand Down
Loading