Skip to content

Commit

Permalink
feat: Add MenuFlyout support
Browse files Browse the repository at this point in the history
- Add support for SuppressIsEnabled for commands alignment
- Add support for XamlUICommand
- FlyoutBase now creates its popup lazily
  • Loading branch information
jeromelaban committed Mar 20, 2020
1 parent d7e5502 commit 4fc3cb1
Show file tree
Hide file tree
Showing 49 changed files with 4,966 additions and 676 deletions.
9 changes: 9 additions & 0 deletions doc/articles/controls/MenuFlyout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# MenuFlyout

MenuFlyout is implemented to provide support for `ContextMenu` and `MenuBar` features.

## Platform specific behavior

On iOS and Android, the flyout can either be displayed using native popup, or Uno managed popups.

The default behavior of the MenuFlyout is to follow the value `FeatureConfiguration.Style.UseUWPDefaultStyles`, but this can be changed per MenuFlyout using the `FlyoutBase.UseNativePopup` property.
Original file line number Diff line number Diff line change
@@ -1,46 +1,75 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.MenuBarTests.SimpleMenuBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.MenuBarTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl x:Class="UITests.Shared.Windows_UI_Xaml_Controls.MenuBarTests.SimpleMenuBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.MenuBarTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<MenuBar>
<MenuBarItem Title="File">
<MenuFlyoutSubItem Text="New">
<MenuFlyoutItem Text="Plain Text Document"/>
<MenuFlyoutItem Text="Rich Text Document"/>
<MenuFlyoutItem Text="Other Formats..."/>
<MenuFlyoutItem Text="Plain Text Document"
Command="{x:Bind MyCommand}" CommandParameter="Plain Text" />
<MenuFlyoutItem Text="Plain Text Document (NoParam)"
Command="{x:Bind MyCommand}" />
<MenuFlyoutItem Text="Rich Text Document"
Click="MenuFlyoutItem_Click" ToolTipService.ToolTip="Rich Text Description" />
<MenuFlyoutItem Text="Other Formats..."
Click="MenuFlyoutItem_Click" />
</MenuFlyoutSubItem>
<MenuFlyoutItem Text="Open..."/>
<MenuFlyoutItem Text="Save"/>
<MenuFlyoutItem x:Name="openMenu"
Icon="MailForward"
Text="Open..."
Click="MenuFlyoutItem_Click" />
<MenuFlyoutItem x:Name="saveMenu"
Icon="Save"
Text="Save"
Click="MenuFlyoutItem_Click"
AccessKey="S">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control"
Key="S" />
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem Text="Exit"/>
<MenuFlyoutItem x:Name="xamlUIMenu"
Command="{x:Bind MyXamlUICommand}" CommandParameter="xamlUIMenu" />
<MenuFlyoutItem x:Name="disabledItem"
Text="Disabled"
IsEnabled="False" />
<MenuFlyoutItem x:Name="exitMenu"
Text="Exit"
Click="MenuFlyoutItem_Click"
AccessKey="X" />
</MenuBarItem>

<MenuBarItem Title="Edit">
<MenuFlyoutItem Text="Undo"/>
<MenuFlyoutItem Text="Cut"/>
<MenuFlyoutItem Text="Copy"/>
<MenuFlyoutItem Text="Paste"/>
<MenuFlyoutItem Text="Undo"
Click="MenuFlyoutItem_Click"/>
<MenuFlyoutItem Text="Cut"
Click="MenuFlyoutItem_Click"/>
<MenuFlyoutItem Text="Copy"
Click="MenuFlyoutItem_Click" />
<MenuFlyoutItem Text="Paste"
Click="MenuFlyoutItem_Click" />
</MenuBarItem>

<MenuBarItem Title="Help">
<MenuFlyoutItem Text="About"/>
<MenuFlyoutItem Text="About"
Click="MenuFlyoutItem_Click"/>
</MenuBarItem>
</MenuBar>
<StackPanel Grid.Row="1">

<TextBlock x:Name="result" />
</StackPanel>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Windows.Input;
using Uno.UI.Common;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
Expand All @@ -26,6 +28,20 @@ public SimpleMenuBar()
this.InitializeComponent();
}

public ICommand MyCommand => new DelegateCommand<object>(param => result.Text = $"command param:{param}");

public ICommand MyXamlUICommand => new XamlUICommand {
Label = "XamlCommand",
Description = "My XamlCommand Description",
Command = new DelegateCommand<object>(param => result.Text = $"xamluicommand param:{param}")
};

private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
{
if (sender is MenuFlyoutItem item)
{
result.Text = $"click text:{item.Text}";
}
}
}
}
4 changes: 4 additions & 0 deletions src/Uno.UI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
SamplesApp\SamplesApp.UnitTests.Shared\SamplesApp.UnitTests.Shared.projitems*{04b1b5eb-d42e-47de-ada0-eb863e5574fd}*SharedItemsImports = 13
SamplesApp\Benchmarks.Shared\Benchmarks.Shared.projitems*{21206058-d5ef-466d-8e4d-ac62357fb479}*SharedItemsImports = 5
SamplesApp\SamplesApp.Shared\SamplesApp.Shared.projitems*{21206058-d5ef-466d-8e4d-ac62357fb479}*SharedItemsImports = 5
SamplesApp\SamplesApp.UnitTests.Shared\SamplesApp.UnitTests.Shared.projitems*{21206058-d5ef-466d-8e4d-ac62357fb479}*SharedItemsImports = 5
SamplesApp\UITests.Shared\UITests.Shared.projitems*{21206058-d5ef-466d-8e4d-ac62357fb479}*SharedItemsImports = 5
SamplesApp\SamplesApp.Shared\SamplesApp.Shared.projitems*{313fcf91-a6db-4585-a23e-49bbeef4784d}*SharedItemsImports = 4
SamplesApp\SamplesApp.UnitTests.Shared\SamplesApp.UnitTests.Shared.projitems*{313fcf91-a6db-4585-a23e-49bbeef4784d}*SharedItemsImports = 4
SamplesApp\SamplesApp.Shared\SamplesApp.Shared.projitems*{3fdf0f2d-cc11-49be-8634-f81638d595c6}*SharedItemsImports = 4
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/Controls/CommandBarRenderer.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected override void Render()
Native.Alpha = (float)Element.Opacity;
}

private IEnumerable<IMenuItem> GetMenuItems(IMenu menu)
private IEnumerable<IMenuItem> GetMenuItems(Android.Views.IMenu menu)
{
for (int i = 0; i < menu.Size(); i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma warning disable 108 // new keyword hiding
#pragma warning disable 114 // new keyword hiding
using System;
using Windows.Foundation;

namespace Windows.UI.Xaml.Controls
{
#if false || false || false || false || false
Expand All @@ -10,53 +13,7 @@ public partial class MenuFlyoutItem : global::Windows.UI.Xaml.Controls.MenuFlyo
// Skipping already declared property Text
// Skipping already declared property CommandParameter
// Skipping already declared property Command
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Controls.IconElement Icon
{
get
{
return (global::Windows.UI.Xaml.Controls.IconElement)this.GetValue(IconProperty);
}
set
{
this.SetValue(IconProperty, value);
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public string KeyboardAcceleratorTextOverride
{
get
{
return (string)this.GetValue(KeyboardAcceleratorTextOverrideProperty);
}
set
{
this.SetValue(KeyboardAcceleratorTextOverrideProperty, value);
}
}
#endif
// Skipping already declared property CommandParameterProperty
// Skipping already declared property CommandProperty
// Skipping already declared property TextProperty
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public static global::Windows.UI.Xaml.DependencyProperty IconProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
"Icon", typeof(global::Windows.UI.Xaml.Controls.IconElement),
typeof(global::Windows.UI.Xaml.Controls.MenuFlyoutItem),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.IconElement)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public static global::Windows.UI.Xaml.DependencyProperty KeyboardAcceleratorTextOverrideProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
"KeyboardAcceleratorTextOverride", typeof(string),
typeof(global::Windows.UI.Xaml.Controls.MenuFlyoutItem),
new FrameworkPropertyMetadata(default(string)));
#endif

// Skipping already declared method Windows.UI.Xaml.Controls.MenuFlyoutItem.MenuFlyoutItem()
// Forced skipping of method Windows.UI.Xaml.Controls.MenuFlyoutItem.MenuFlyoutItem()
// Forced skipping of method Windows.UI.Xaml.Controls.MenuFlyoutItem.Text.get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
#endif
public partial class MenuFlyoutSeparator : global::Windows.UI.Xaml.Controls.MenuFlyoutItemBase
public partial class MenuFlyoutSeparator : MenuFlyoutItemBase
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public MenuFlyoutSeparator()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.MenuFlyoutSeparator", "MenuFlyoutSeparator.MenuFlyoutSeparator()");
}
#endif
// Forced skipping of method Windows.UI.Xaml.Controls.MenuFlyoutSeparator.MenuFlyoutSeparator()
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
#pragma warning disable 108 // new keyword hiding
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Input
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
#endif
public partial class CanExecuteRequestedEventArgs
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public bool CanExecute
{
get
{
throw new global::System.NotImplementedException("The member bool CanExecuteRequestedEventArgs.CanExecute is not implemented in Uno.");
}
set
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Input.CanExecuteRequestedEventArgs", "bool CanExecuteRequestedEventArgs.CanExecute");
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public object Parameter
{
get
{
throw new global::System.NotImplementedException("The member object CanExecuteRequestedEventArgs.Parameter is not implemented in Uno.");
}
}
#endif
// Forced skipping of method Windows.UI.Xaml.Input.CanExecuteRequestedEventArgs.Parameter.get
// Forced skipping of method Windows.UI.Xaml.Input.CanExecuteRequestedEventArgs.CanExecute.get
// Forced skipping of method Windows.UI.Xaml.Input.CanExecuteRequestedEventArgs.CanExecute.set
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,4 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Input
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
#endif
public partial class ExecuteRequestedEventArgs
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public object Parameter
{
get
{
throw new global::System.NotImplementedException("The member object ExecuteRequestedEventArgs.Parameter is not implemented in Uno.");
}
}
#endif
// Forced skipping of method Windows.UI.Xaml.Input.ExecuteRequestedEventArgs.Parameter.get
}
}
Loading

0 comments on commit 4fc3cb1

Please sign in to comment.