- Notifications
You must be signed in to change notification settings - Fork 1.4k
Classic menu #1086
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
Classic menu #1086
Conversation
/// </summary> | ||
public static readonly DependencyProperty OrientationProperty = | ||
DependencyProperty.Register( | ||
"Orientation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameof()
var menuItem = item as MenuFlyoutItemBase; | ||
if (menuItem != null) | ||
{ | ||
menuFlyout.Items?.Add(menuItem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You created menuFlyout, how would Items be null? is the ?. needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not needed
| ||
private void ClassicMenu_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
var wrapPanel = (WrapPanel.WrapPanel)ItemsPanelRoot; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably do ItemsPanelRoot as WrapPanel.WrapPanel given someone could change the ItemsPanel in the template. At which point, you should probably add checks for the main basic types of panel that contain an orientation property.
var wrapPanel = (WrapPanel.WrapPanel)ItemsPanelRoot; | ||
wrapPanel.Orientation = Orientation; | ||
| ||
Dispatcher.AcceleratorKeyActivated -= Dispatcher_AcceleratorKeyActivated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than here, when are these events every unsubscribed from? Should probably unsubscribe in the Unloaded event too.
static ClassicMenu() | ||
{ | ||
MenuItemInputGestureCache = | ||
new Dictionary<string, MenuFlyoutItem>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this on a new line? Better yet, why is this needed at all? Just instantiate the dictionary where it's declared.
/// <inheritdoc /> | ||
protected override void OnApplyTemplate() | ||
{ | ||
Loaded -= ClassicMenu_Loaded; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference: I would move this line into the Loaded event handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I would agree with this, but we run into issues if the user sets NavigationCacheMode. If we subscribe to the events in OnApplyTemplate and unsubscribe within the event handlers then we would not get the events the next time the page is hit.
} | ||
| ||
/// <summary> | ||
/// this method is used to show the menu for current item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upper case T please.
@@ -0,0 +1,123 @@ | |||
<Page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect xaml in this file
| ||
private void ClassicMenu_Unloaded(object sender, RoutedEventArgs e) | ||
{ | ||
Dispatcher.AcceleratorKeyActivated -= Dispatcher_AcceleratorKeyActivated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be a stickler, unsubscribe from the Unloaded event in here too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be done automatically ? Once the page is unloaded all events, properties should destroyed !!
Regarding the general events like Dispatcher.AcceleratorKeyActivated it make sense to unsubscribe at unloaded but does unsubscribe from unload event here helps ? :)
/// </summary> | ||
public partial class ClassicMenu | ||
{ | ||
private static bool NavigateThrowMenuHeader(KeyEventArgs args, ClassicMenu menu, ClassicMenuItem menuItem, Orientation orientation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised what this method is actually for. It should be called NavigateThroughMenuHeader.
@deltakosh I need an icon for the classic menu :) |
private static readonly Dictionary<string, MenuFlyoutItem> MenuItemInputGestureCache = new Dictionary<string, MenuFlyoutItem>(); | ||
| ||
/// <summary> | ||
/// Gets or sets the orientation of the Classic menu, Horizontal or vertical means that child controls will be added horizontally until the width of the panel can't fit more control then a new row is added to fit new horizontal added child controls, vertical means that child will be added vertically until the height of the panel is recieved then a new column is added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a few carriage returns please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not following what to do here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments in XML-docs are too long. You should split into multiple lines to make it more easy to read.
/// <summary> | ||
/// Initializes a new instance of the <see cref="ClassicMenu"/> class. | ||
/// </summary> | ||
public ClassicMenu() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the ctor above the properties please. More of a personal preference than a must have
{ | ||
"Name": "ClassicMenu", | ||
"Type": "ClassicMenuPage", | ||
"About": "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need some information about this control
| ||
<Grid Background="{StaticResource Brush-Grey-05}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="1*" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Height should be Auto. Looks odd having the huge space between the Menu and the page content. At first I thought it was bad sizing on the part of the menu itself
</MenuFlyoutSubItem> | ||
</controls:ClassicMenuItem> | ||
| ||
<controls:ClassicMenuItem Header="View" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept clicking these items expecting a menu to open. Let's add items to these
/// <summary> | ||
/// Gets or sets the menu style for ClassicMenuItem | ||
/// </summary> | ||
public Style MenuStyle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would each menu item have it's own menu style? wouldn't you want them all to be the same?
/// <summary> | ||
/// Gets or sets the MenuBackground to appear in the title bar | ||
/// </summary> | ||
public string MenuBackground |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would each menu item have it's own menu background? Wouldn't you want them all to be the same?
: FlyoutPlacementMode.Right; | ||
menuFlyout.MenuFlyoutPresenterStyle = MenuStyle; | ||
| ||
foreach (var item in Items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an ItemsControl the ItemsSource could be bound to a backing collection and the items would not be menu flyouts. Should account for that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
menuFlyout.Items.Add accepts only MenuFlyoutItemBase.
can you share how to limit the item source because I tried several approach with no luck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make it not an ItemsControl and have your own collection of Items
/// <summary> | ||
/// Classic Menu Item is the items main container for Class Menu control | ||
/// </summary> | ||
public class ClassicMenuItem : ItemsControl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Classic MenuItem? Why not just MenuItem?
/// <summary> | ||
/// Classic Menu Control defines a menu of choices for users to invoke. | ||
/// </summary> | ||
public partial class ClassicMenu : ItemsControl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Classic Menu? Why not just Menu?
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="local:ClassicMenuItem"> | ||
<Button x:Name="FlyoutButton" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of keeping track of the Button, add the MenuFlyout within the xaml and access that within OnApplyTemplate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but it didn't work so I used the button instead.
I will push new changes, please don't review as final review |
<Page.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="MenuStyles.xaml" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be safely removed
| ||
</Page.Resources> | ||
| ||
<Grid Background="{StaticResource Brush-Grey-05}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove custom brushes from the bind file
<RowDefinition Height="auto" /> | ||
</Grid.RowDefinitions> | ||
| ||
<controls:Menu RequestedTheme="Light" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you are specifically requesting Light theme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was for testing purposes no need for it.
| ||
/// <summary> | ||
/// Gets or sets the orientation of the Menu, Horizontal or vertical means that child controls will be added horizontally | ||
/// until the width of the panel can't fit more control then a new row is added to fit new horizontal added child controls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Trailing whitespace to fix warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved but should still get all the warnings removed.
| ||
<Style TargetType="local:MenuItem"> | ||
<Setter Property="IsTabStop" Value="True" /> | ||
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the menu items should have a transparent background by default. This is what users would expect from a Menu
/// <summary> | ||
/// Gets the current selected menu header item | ||
/// </summary> | ||
public MenuItem SelectedHeaderItem { get; internal set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be SelectedMenuItem?
| ||
/// <summary> | ||
/// Gets or sets the orientation of the Menu, Horizontal or vertical means that child controls will be added horizontally | ||
/// until the width of the panel can't fit more control then a new row is added to fit new horizontal added child controls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved but should still get all the warnings removed.
Creating new control Classic Menu #981