Skip to content

Conversation

IbraheemOsama
Copy link
Member

@IbraheemOsama IbraheemOsama commented Apr 9, 2017

Creating new control Classic Menu #981

@IbraheemOsama IbraheemOsama added this to the v1.5 milestone Apr 9, 2017
/// </summary>
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register(
"Orientation",
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Member Author

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;
Copy link
Contributor

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;
Copy link
Contributor

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>();
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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 :)

Copy link
Member Author

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)
Copy link
Contributor

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.

@IbraheemOsama
Copy link
Member Author

@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
Copy link
Contributor

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

Copy link
Member Author

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 ?

Copy link
Contributor

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()
Copy link
Contributor

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": "",
Copy link
Contributor

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*" />
Copy link
Contributor

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" />
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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"
Copy link
Contributor

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

Copy link
Member Author

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.

@IbraheemOsama
Copy link
Member Author

I will push new changes, please don't review as final review

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MenuStyles.xaml" />
Copy link
Contributor

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}">
Copy link
Contributor

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"
Copy link
Contributor

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?

Copy link
Member Author

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.

@IbraheemOsama
Copy link
Member Author

@nmetulev @skendrot I won't say "now the PR contains everything", last time I said so I received more comments :D


/// <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,
Copy link
Contributor

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

Copy link
Contributor

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}" />
Copy link
Contributor

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; }
Copy link
Contributor

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,
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment