Skip to content

Commit

Permalink
Update AppUIBasics
Browse files Browse the repository at this point in the history
- Fix issue #681: NavigationMenuItem was renamed to NavigationViewItem
- Update SystemControlRevealBorderListMediumBrush to SystemControlBackgroundListMediumRevealBorderBrush
  • Loading branch information
supratiksen authored and oldnewthing committed Jul 13, 2017
1 parent 2867cc1 commit b3b1940
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Samples/XamlUIBasics/cs/AppUIBasics/AppUIBasics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<AssemblyName>AppUIBasics</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.16190.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16190.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.16232.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16232.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile>
<FileAlignment>512</FileAlignment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RowDefinition />
</Grid.RowDefinitions>
<CheckBox Content="Show Settings button" x:Name="settingsCheck" />
<controls:NavigationView Loaded="NavigationView_Loaded" Margin="0,12,0,0" Grid.Row="1" SettingsInvoked="NavigationView_SettingsInvoked"
<controls:NavigationView Loaded="NavigationView_Loaded" Margin="0,12,0,0" Grid.Row="1" SelectionChanged="NavigationView_SelectionChanged"
x:Name="nvSample"
IsSettingsVisible="{Binding ElementName=settingsCheck,Path=IsChecked}" IsTabStop="False"
Header="This is header text.">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AppUIBasics.SamplePages;
using System;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;

Expand All @@ -15,35 +16,22 @@ public NavigationViewPage()
{
this.InitializeComponent();

AddMenuItem(Symbol.Play, "Menu Item1", NavigationMenuItem_Invoked);
AddMenuItem(Symbol.Save, "Menu Item2", NavigationMenuItem_Invoked_1);
AddMenuItem(Symbol.Refresh, "Menu Item3", NavigationMenuItem_Invoked_2);
AddMenuItem(Symbol.Play, "Menu Item1", typeof(SamplePage1));
AddMenuItem(Symbol.Save, "Menu Item2", typeof(SamplePage2));
AddMenuItem(Symbol.Refresh, "Menu Item3", typeof(SamplePage3));
}

private void AddMenuItem(Symbol icon, string text, TypedEventHandler<NavigationMenuItem, object> handler)
private void AddMenuItem(Symbol icon, string text, Type pageType)
{
var item = new NavigationMenuItem() {
var item = new NavigationViewItem()
{
Icon = new SymbolIcon(icon),
Text = text };
item.Invoked += handler;
Content = text,
Tag = pageType
};
nvSample.MenuItems.Add(item);
}

private void NavigationMenuItem_Invoked(Windows.UI.Xaml.Controls.NavigationMenuItem sender, object args)
{
contentFrame.Navigate(typeof(SamplePage1));
}

private void NavigationMenuItem_Invoked_1(Windows.UI.Xaml.Controls.NavigationMenuItem sender, object args)
{
contentFrame.Navigate(typeof(SamplePage2));
}

private void NavigationMenuItem_Invoked_2(Windows.UI.Xaml.Controls.NavigationMenuItem sender, object args)
{
contentFrame.Navigate(typeof(SamplePage3));
}

private void NavigationView_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
contentFrame.Navigate(typeof(SamplePage1));
Expand All @@ -54,9 +42,18 @@ private void rootGrid_SizeChanged(object sender, Windows.UI.Xaml.SizeChangedEven
Example1.Width = e.NewSize.Width;
}

private void NavigationView_SettingsInvoked(Windows.UI.Xaml.Controls.NavigationView sender, object args)
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
contentFrame.Navigate(typeof(SampleSettingsPage));
if (args.IsSettingsSelected)
{
contentFrame.Navigate(typeof(SampleSettingsPage));
}
else
{
var selectedItem = (NavigationViewItem)args.SelectedItem;
Type pageType = (Type)selectedItem.Tag;
contentFrame.Navigate(pageType);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<local:ControlExample x:Name="Example1" HeaderText="A simple RatingsControl">
<local:ControlExample.Example>
<StackPanel>
<controls:RatingsControl x:Name="ratingsControl1"
<controls:RatingControl x:Name="ratingsControl1"
IsClearEnabled="{x:Bind clearEnabledCheck.IsChecked.Value, Mode=OneWay}"
IsReadOnly="{x:Bind readOnlyCheck.IsChecked.Value, Mode=OneWay}" HorizontalAlignment="Left" />
<StackPanel Orientation="Horizontal" Margin="0,12,0,0">
Expand All @@ -32,7 +32,7 @@
<StackPanel>
<Slider x:Name="slider" Header="Use slider to change placeholder value" Minimum="0" Maximum="5"
StepFrequency="0.5" SmallChange="0.5" IsFocusEngagementEnabled="False"/>
<controls:RatingsControl x:Name="ratingsControl2" HorizontalAlignment="Left"
<controls:RatingControl x:Name="ratingsControl2" HorizontalAlignment="Left"
PlaceholderValue="{x:Bind slider.Value, Mode=TwoWay}" />
</StackPanel>
</local:ControlExample.Example>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@
<local:ControlExample x:Name="Example2" RelativePanel.AlignLeftWith="Example1" RelativePanel.Below="Example1" HeaderText="RevealBorderBrush applied on a Grid" Grid.Column="1">
<local:ControlExample.Example>
<StackPanel VerticalAlignment="Center">
<Grid BorderThickness="3" BorderBrush="{ThemeResource SystemControlRevealBorderListMediumBrush}" Height="100" >
<TextBlock Text="SystemControlRevealBorderListMediumBrush"/>
<Grid BorderThickness="3" BorderBrush="{ThemeResource SystemControlBackgroundListMediumRevealBorderBrush}" Height="100" >
<TextBlock Text="SystemControlBackgroundListMediumRevealBorderBrush"/>
</Grid>
</StackPanel>
</local:ControlExample.Example>
<local:ControlExample.Xaml>
<RichTextBlock>
<Paragraph>&lt;Grid BorderThickness="3" BorderBrush="{ThemeResource SystemControlRevealBorderListMediumBrush}"&gt;</Paragraph>
<Paragraph>&lt;Grid BorderThickness="3" BorderBrush="{ThemeResource SystemControlBackgroundListMediumRevealBorderBrush}"&gt;</Paragraph>
<Paragraph TextIndent="12">&lt;TextBlock Text="SystemControlRevealBorderChromeWhiteBrush" /&gt;</Paragraph>
<Paragraph>&lt;/Grid&gt;</Paragraph>
</RichTextBlock>
Expand Down
4 changes: 2 additions & 2 deletions Samples/XamlUIBasics/cs/AppUIBasics/ItemPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private async void navigationHelper_LoadState(object sender, LoadStateEventArgs
}

ControlInfoDataGroup group = await ControlInfoDataSource.GetGroupFromItemAsync((String)e.NavigationParameter);
var menuItem = ((NavigationMenuItem)NavigationRootPage.Current.NavigationView.MenuItems.FirstOrDefault(m => m.Tag?.ToString() == group.UniqueId));
var menuItem = NavigationRootPage.Current.NavigationView.MenuItems.Cast<NavigationViewItem>().FirstOrDefault(m => m.Tag?.ToString() == group.UniqueId);
if (menuItem != null)
{
menuItem.IsSelected = true;
Expand Down Expand Up @@ -285,7 +285,7 @@ private void svPanel_KeyDown(object sender, KeyRoutedEventArgs e)
if (e.Key == VirtualKey.Up)
{
var nextElement = FocusManager.FindNextElement(FocusNavigationDirection.Up);
if (nextElement.GetType() == typeof(NavigationMenuItem))
if (nextElement.GetType() == typeof(NavigationViewItem))
{
NavigationRootPage.Current.PageHeader.Focus(FocusState.Programmatic);
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/XamlUIBasics/cs/AppUIBasics/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);

var firstMenuItem = (NavigationMenuItem)NavigationRootPage.Current.NavigationView.MenuItems.FirstOrDefault();
var firstMenuItem = (NavigationViewItem)NavigationRootPage.Current.NavigationView.MenuItems.FirstOrDefault();
if (firstMenuItem != null)
firstMenuItem.IsSelected = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</Grid.ColumnDefinitions>
<Rectangle Fill="{ThemeResource NavigationViewDefaultPaneBackground}" x:Name="XboxContentSafeRect" Width="48" Visibility="Collapsed" />
<controls:NavigationView x:Name="NavigationViewControl" AlwaysShowHeader="True" Header=" " Grid.Column="1" IsTabStop="False"
SettingsInvoked="NavigationView_SettingsInvoked" Loaded="NavigationViewControl_Loaded">
SelectionChanged="NavigationView_SelectionChanged" Loaded="NavigationViewControl_Loaded">
<controls:NavigationView.HeaderTemplate>
<DataTemplate>
<local:PageHeader Title="{Binding}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public PageHeader PageHeader

private RootFrameNavigationHelper rootFrameNavigationHelper;

private NavigationMenuItem AllControlsMenuItem;
public NavigationMenuItem NewControlsMenuItem;
private NavigationViewItem AllControlsMenuItem;
public NavigationViewItem NewControlsMenuItem;

public NavigationRootPage()
{
Expand Down Expand Up @@ -150,9 +150,8 @@ private void AddNavigationMenuItems()
{
foreach (var g in Groups)
{
var item = new NavigationMenuItem() { Text = g.Title, Tag = g.UniqueId, DataContext = g };
var item = new NavigationViewItem() { Content = g.Title, Tag = g.UniqueId, DataContext = g };
AutomationProperties.SetName(item, g.Title);
item.Invoked += NavigationMenuItem_Invoked;
if (g.ImagePath.ToLowerInvariant().EndsWith(".png"))
{
item.Icon = new BitmapIcon() { UriSource = new Uri(g.ImagePath, UriKind.RelativeOrAbsolute) };
Expand All @@ -167,10 +166,10 @@ private void AddNavigationMenuItems()
}
NavigationViewControl.MenuItems.Add(item);
}
this.AllControlsMenuItem = (NavigationMenuItem)NavigationViewControl.MenuItems[0];
this.AllControlsMenuItem = (NavigationViewItem)NavigationViewControl.MenuItems[0];
AllControlsMenuItem.Loaded += AllControlsMenuItem_Loaded;

this.NewControlsMenuItem = (NavigationMenuItem)NavigationViewControl.MenuItems[1];
this.NewControlsMenuItem = (NavigationViewItem)NavigationViewControl.MenuItems[1];
}

private void NavigationRootPage_KeyDown(object sender, KeyRoutedEventArgs e)
Expand All @@ -192,7 +191,7 @@ private void CoreTitleBar_IsVisibleChanged(CoreApplicationViewTitleBar sender, o
BackButtonGrid.Visibility = Visibility.Visible;
DeviceFamily = DeviceType.Desktop;
XboxContentSafeRect.Visibility = Visibility.Collapsed;
NavigationViewControl.GetDescendantsOfType<NavigationMenuItem>().Where(c => c.Name == "SettingsNavPaneItem").First().Margin = new Thickness(0);
NavigationViewControl.GetDescendantsOfType<NavigationViewItem>().Where(c => c.Name == "SettingsNavPaneItem").First().Margin = new Thickness(0);

}

Expand All @@ -204,7 +203,7 @@ void updateTitleBar()
DeviceFamily = DeviceType.Mobile;
BackButtonGrid.Visibility = Visibility.Collapsed;
XboxContentSafeRect.Visibility = Visibility.Collapsed;
NavigationViewControl.GetDescendantsOfType<NavigationMenuItem>().Where(c => c.Name == "SettingsNavPaneItem").First().Margin = new Thickness(0);
NavigationViewControl.GetDescendantsOfType<NavigationViewItem>().Where(c => c.Name == "SettingsNavPaneItem").First().Margin = new Thickness(0);

}
//xbox
Expand All @@ -213,7 +212,7 @@ void updateTitleBar()
DeviceFamily = DeviceType.Xbox;
BackButtonGrid.Visibility = Visibility.Collapsed;
XboxContentSafeRect.Visibility = Visibility.Visible;
NavigationViewControl.GetDescendantsOfType<NavigationMenuItem>().Where(c => c.Name == "SettingsNavPaneItem").First().Margin = new Thickness(0, 0, 0, 40);
NavigationViewControl.GetDescendantsOfType<NavigationViewItem>().Where(c => c.Name == "SettingsNavPaneItem").First().Margin = new Thickness(0, 0, 0, 40);

}
}
Expand All @@ -226,7 +225,7 @@ private async void LoadGroups()

if (NavigationRootPage.Current != null)
{
var menuItem = (NavigationMenuItem)NavigationRootPage.Current.NavigationView.MenuItems.FirstOrDefault();
var menuItem = (NavigationViewItem)NavigationRootPage.Current.NavigationView.MenuItems.FirstOrDefault();
if (menuItem != null)
menuItem.IsSelected = true;
}
Expand All @@ -235,27 +234,28 @@ private async void LoadGroups()
GroupsLoaded(this, new EventArgs());
}

private void NavigationView_SettingsInvoked(NavigationView sender, object args)
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
rootFrame.Navigate(typeof(SettingsPage));
}

private void NavigationMenuItem_Invoked(NavigationMenuItem sender, object args)
{
if (sender == AllControlsMenuItem)
if (args.IsSettingsSelected)
{
rootFrame.Navigate(typeof(SettingsPage));
}
else if (args.SelectedItem == AllControlsMenuItem)
{
rootFrame.Navigate(typeof(MainPage));
}
else if (sender == NewControlsMenuItem)
else if (args.SelectedItem == NewControlsMenuItem)
{
rootFrame.Navigate(typeof(NewControlsPage));
}
else
{
var itemId = ((ControlInfoDataGroup)sender.DataContext).UniqueId;
var selectedItem = (NavigationViewItem)args.SelectedItem;
var itemId = ((ControlInfoDataGroup)selectedItem.DataContext).UniqueId;
rootFrame.Navigate(typeof(SectionPage), itemId);
}
}

private void rootFrame_Navigated(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
SetCustomBackButtonVisibility();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void itemGridView_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRouted
if (e.Key == Windows.System.VirtualKey.Up)
{
var nextElement = FocusManager.FindNextElement(FocusNavigationDirection.Up);
if (nextElement.GetType() == typeof(NavigationMenuItem))
if (nextElement.GetType() == typeof(NavigationViewItem))
{
pageHeader.Focus(FocusState.Programmatic);
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/XamlUIBasics/cs/AppUIBasics/SectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private async void navigationHelper_LoadState(object sender, LoadStateEventArgs
var group = await ControlInfoDataSource.GetGroupAsync((String)e.NavigationParameter);
Group = group;
Bindings.Update();
((NavigationMenuItem)NavigationRootPage.Current.NavigationView.MenuItems.FirstOrDefault(m => m.Tag?.ToString() == group.UniqueId)).IsSelected = true;
NavigationRootPage.Current.NavigationView.MenuItems.Cast<NavigationViewItem>().FirstOrDefault(m => m.Tag?.ToString() == group.UniqueId).IsSelected = true;
NavigationRootPage.Current.NavigationView.Header = group?.Title;
}

Expand Down

0 comments on commit b3b1940

Please sign in to comment.