Skip to content

Commit e8d2bca

Browse files
Luke BlevinsLuke Blevins
authored andcommitted
Fixed NavView Selected Item Not Moving With Navigation Actions
1 parent c88067e commit e8d2bca

File tree

6 files changed

+480
-91
lines changed

6 files changed

+480
-91
lines changed

FileLoader.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Windows.Storage.Search;
2525
using Windows.UI.Popups;
2626
using Interact;
27+
using Windows.UI.Xaml.Controls;
2728

2829
namespace ItemListPresenter
2930
{
@@ -53,6 +54,13 @@ public class ItemViewModel
5354
public static ObservableCollection<ListedItem> filesAndFolders = new ObservableCollection<ListedItem>();
5455
public static ObservableCollection<ListedItem> FilesAndFolders { get { return filesAndFolders; } }
5556

57+
string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
58+
string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
59+
string DownloadsPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads";
60+
string OneDrivePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\OneDrive";
61+
string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
62+
string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
63+
string VideosPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
5664

5765
StorageFolder folder;
5866
string gotName;
@@ -114,11 +122,16 @@ public static ProgressUIVisibility PVIS
114122

115123
public ItemViewModel(string ViewPath)
116124
{
117-
GenericFileBrowser.P.path = ViewPath;
118-
119-
FilesAndFolders.Clear();
120-
GetItemsAsync(ViewPath);
125+
126+
127+
GenericFileBrowser.P.path = ViewPath;
128+
FilesAndFolders.Clear();
129+
GetItemsAsync(ViewPath);
130+
131+
132+
121133
History.AddToHistory(ViewPath);
134+
122135

123136

124137

ItemInteractions.cs

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using Windows.UI.Popups;
2929
using Windows.UI.Xaml.Media;
3030
using System.Collections.ObjectModel;
31+
using Windows.UI.Xaml.Media.Animation;
3132

3233
namespace Interact
3334
{
@@ -66,8 +67,117 @@ public static async void List_ItemClick(object sender, DoubleTappedRoutedEventAr
6667
History.ForwardList.Clear();
6768
ItemViewModel.FS.isEnabled = false;
6869
ItemViewModel.FilesAndFolders.Clear();
69-
ItemViewModel.ViewModel = new ItemViewModel(clickedOnItem.FilePath);
70-
GenericFileBrowser.P.path = clickedOnItem.FilePath;
70+
if (clickedOnItem.FilePath == Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
71+
{
72+
GenericFileBrowser.P.path = "Desktop";
73+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
74+
{
75+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "DesktopIC")
76+
{
77+
MainPage.Select.itemSelected = NavItemChoice;
78+
break;
79+
}
80+
}
81+
MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), YourHome.DesktopPath, new SuppressNavigationTransitionInfo());
82+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Desktop";
83+
}
84+
else if (clickedOnItem.FilePath == Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
85+
{
86+
GenericFileBrowser.P.path = "Documents";
87+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
88+
{
89+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "DocumentsIC")
90+
{
91+
MainPage.Select.itemSelected = NavItemChoice;
92+
break;
93+
}
94+
}
95+
MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), YourHome.DocumentsPath, new SuppressNavigationTransitionInfo());
96+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Documents";
97+
}
98+
else if (clickedOnItem.FilePath == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"))
99+
{
100+
GenericFileBrowser.P.path = "Downloads";
101+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
102+
{
103+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "DownloadsIC")
104+
{
105+
MainPage.Select.itemSelected = NavItemChoice;
106+
break;
107+
}
108+
}
109+
MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), YourHome.DownloadsPath, new SuppressNavigationTransitionInfo());
110+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Downloads";
111+
}
112+
else if (clickedOnItem.FilePath == Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))
113+
{
114+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
115+
{
116+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "PicturesIC")
117+
{
118+
MainPage.Select.itemSelected = NavItemChoice;
119+
break;
120+
}
121+
}
122+
MainPage.accessibleContentFrame.Navigate(typeof(PhotoAlbum), YourHome.PicturesPath, new SuppressNavigationTransitionInfo());
123+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Pictures";
124+
GenericFileBrowser.P.path = "Pictures";
125+
}
126+
else if (clickedOnItem.FilePath == Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))
127+
{
128+
GenericFileBrowser.P.path = "Music";
129+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
130+
{
131+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "MusicIC")
132+
{
133+
MainPage.Select.itemSelected = NavItemChoice;
134+
break;
135+
}
136+
}
137+
MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), YourHome.MusicPath, new SuppressNavigationTransitionInfo());
138+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Music";
139+
}
140+
else if(clickedOnItem.FilePath == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\OneDrive"))
141+
{
142+
GenericFileBrowser.P.path = "OneDrive";
143+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
144+
{
145+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "OneD_IC")
146+
{
147+
MainPage.Select.itemSelected = NavItemChoice;
148+
break;
149+
}
150+
}
151+
MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), YourHome.OneDrivePath, new SuppressNavigationTransitionInfo());
152+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search OneDrive";
153+
}
154+
else if (clickedOnItem.FilePath == Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))
155+
{
156+
GenericFileBrowser.P.path = "Videos";
157+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
158+
{
159+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "VideosIC")
160+
{
161+
MainPage.Select.itemSelected = NavItemChoice;
162+
break;
163+
}
164+
}
165+
MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), YourHome.VideosPath, new SuppressNavigationTransitionInfo());
166+
MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Videos";
167+
}
168+
else
169+
{
170+
GenericFileBrowser.P.path = clickedOnItem.FilePath;
171+
foreach (NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
172+
{
173+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "LocD_IC")
174+
{
175+
MainPage.Select.itemSelected = NavItemChoice;
176+
break;
177+
}
178+
}
179+
ItemViewModel.ViewModel = new ItemViewModel(clickedOnItem.FilePath);
180+
}
71181
GenericFileBrowser.UpdateAllBindings();
72182
}
73183
else if (clickedOnItem.FileExtension == "Executable")

MainPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<Grid Tag="{x:Bind Tag, Mode=OneWay}" Background="Transparent" Name="DragArea" HorizontalAlignment="Stretch" Height="34" VerticalAlignment="Top" Margin="55,0,200,0" Canvas.ZIndex="5"/>
3333

34-
<NavigationView RequestedTheme="Default" SelectedItem="{x:Bind local:MainPage.Select.itemSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:FieldModifier="public" AlwaysShowHeader="False" IsPaneOpen="True" Loaded="navView_Loaded" IsBackButtonVisible="Collapsed" IsSettingsVisible="True" x:Name="navView" SelectionChanged="navView_ItemSelected" VerticalAlignment="Stretch" >
34+
<NavigationView RequestedTheme="Default" SelectedItem="{x:Bind local:MainPage.Select.itemSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:FieldModifier="public" AlwaysShowHeader="False" IsPaneOpen="True" Loaded="navView_Loaded" IsBackButtonVisible="Collapsed" IsSettingsVisible="True" x:Name="navView" ItemInvoked="NavView_ItemInvoked" SelectionChanged="navView_ItemSelected" VerticalAlignment="Stretch" >
3535

3636

3737
<NavigationView.MenuItems>

MainPage.xaml.cs

Lines changed: 87 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616

17+
using Interact;
1718
using ItemListPresenter;
1819
using System;
1920
using System.ComponentModel;
@@ -30,6 +31,8 @@ namespace Files
3031
public sealed partial class MainPage : Page
3132
{
3233
public static NavigationView nv;
34+
public static Frame accessibleContentFrame;
35+
public static AutoSuggestBox accessibleAutoSuggestBox;
3336
string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
3437
string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
3538
string DownloadsPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads";
@@ -41,7 +44,7 @@ public MainPage()
4144
{
4245
this.InitializeComponent();
4346
this.IsTextScaleFactorEnabled = true;
44-
47+
accessibleContentFrame = ContentFrame;
4548
var CoreTitleBar = CoreApplication.GetCurrentView().TitleBar;
4649
CoreTitleBar.ExtendViewIntoTitleBar = true;
4750
Window.Current.SetTitleBar(DragArea);
@@ -50,7 +53,7 @@ public MainPage()
5053
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
5154
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
5255
nv = navView;
53-
56+
accessibleAutoSuggestBox = auto_suggest;
5457
}
5558

5659
private static SelectItem select = new SelectItem();
@@ -59,91 +62,108 @@ public MainPage()
5962
private void navView_ItemSelected(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
6063
{
6164
NavigationViewItem item = args.SelectedItem as NavigationViewItem;
65+
6266

63-
if (item.Name == "homeIc")
64-
{
65-
ContentFrame.Navigate(typeof(YourHome));
66-
auto_suggest.PlaceholderText = "Search Recents";
67-
}
68-
else if (item.Name == "DesktopIC")
69-
{
70-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
71-
ContentFrame.Navigate(typeof(GenericFileBrowser), DesktopPath);
72-
auto_suggest.PlaceholderText = "Search Desktop";
73-
}
74-
else if (item.Name == "DocumentsIC")
75-
{
76-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
77-
ContentFrame.Navigate(typeof(GenericFileBrowser), DocumentsPath);
78-
auto_suggest.PlaceholderText = "Search Documents";
79-
}
80-
else if (item.Name == "DownloadsIC")
81-
{
82-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
83-
ContentFrame.Navigate(typeof(GenericFileBrowser), DownloadsPath);
84-
auto_suggest.PlaceholderText = "Search Downloads";
85-
}
86-
else if (item.Name == "PicturesIC")
87-
{
88-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
89-
ContentFrame.Navigate(typeof(PhotoAlbum), PicturesPath);
90-
auto_suggest.PlaceholderText = "Search Pictures";
91-
}
92-
else if (item.Name == "MusicIC")
93-
{
94-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
95-
ContentFrame.Navigate(typeof(GenericFileBrowser), MusicPath);
96-
auto_suggest.PlaceholderText = "Search Music";
97-
}
98-
else if (item.Name == "VideosIC")
67+
if (item.Content.Equals("Settings"))
9968
{
100-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
101-
ContentFrame.Navigate(typeof(GenericFileBrowser), VideosPath);
102-
auto_suggest.PlaceholderText = "Search Videos";
103-
}
104-
else if (item.Name == "LocD_IC")
105-
{
106-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
107-
ContentFrame.Navigate(typeof(GenericFileBrowser), @"C:\");
108-
auto_suggest.PlaceholderText = "Search";
109-
}
110-
else if (item.Name == "OneD_IC")
111-
{
112-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
113-
ContentFrame.Navigate(typeof(GenericFileBrowser), OneDrivePath);
114-
auto_suggest.PlaceholderText = "Search OneDrive";
115-
}
116-
else if(item.Content.Equals("Settings"))
117-
{
118-
ContentFrame.Navigate(typeof(Settings));
69+
//ContentFrame.Navigate(typeof(Settings));
11970
}
12071
}
12172

122-
123-
73+
74+
12475

12576
private void auto_suggest_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
12677
{
127-
78+
12879
}
12980

13081
private void navView_Loaded(object sender, RoutedEventArgs e)
13182
{
132-
133-
foreach (NavigationViewItemBase item in navView.MenuItems)
83+
84+
foreach (NavigationViewItemBase NavItemChoice in nv.MenuItems)
13485
{
135-
if(item is NavigationViewItem && item.Name.ToString() == "homeIc")
86+
if (NavItemChoice is NavigationViewItem && NavItemChoice.Name.ToString() == "homeIc")
13687
{
137-
Select.itemSelected = item;
88+
Select.itemSelected = NavItemChoice;
13889
break;
13990
}
14091
}
92+
ContentFrame.Navigate(typeof(YourHome));
14193
auto_suggest.IsEnabled = true;
14294
auto_suggest.PlaceholderText = "Search Recents";
14395
}
144-
}
14596

97+
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
98+
{
99+
100+
var item = args.InvokedItem;
101+
102+
//var item = Interaction.FindParent<NavigationViewItemBase>(args.InvokedItem as DependencyObject);
103+
if (args.IsSettingsInvoked == true)
104+
{
105+
ContentFrame.Navigate(typeof(Settings));
106+
}
107+
else
108+
{
109+
if (item.ToString() == "Home")
110+
{
111+
ContentFrame.Navigate(typeof(YourHome));
112+
auto_suggest.PlaceholderText = "Search Recents";
113+
}
114+
else if (item.ToString() == "Desktop")
115+
{
116+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
117+
ContentFrame.Navigate(typeof(GenericFileBrowser), DesktopPath);
118+
auto_suggest.PlaceholderText = "Search Desktop";
119+
}
120+
else if (item.ToString() == "Documents")
121+
{
122+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
123+
ContentFrame.Navigate(typeof(GenericFileBrowser), DocumentsPath);
124+
auto_suggest.PlaceholderText = "Search Documents";
125+
}
126+
else if (item.ToString() == "Downloads")
127+
{
128+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
129+
ContentFrame.Navigate(typeof(GenericFileBrowser), DownloadsPath);
130+
auto_suggest.PlaceholderText = "Search Downloads";
131+
}
132+
else if (item.ToString() == "Pictures")
133+
{
134+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
135+
ContentFrame.Navigate(typeof(PhotoAlbum), PicturesPath);
136+
auto_suggest.PlaceholderText = "Search Pictures";
137+
}
138+
else if (item.ToString() == "Music")
139+
{
140+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
141+
ContentFrame.Navigate(typeof(GenericFileBrowser), MusicPath);
142+
auto_suggest.PlaceholderText = "Search Music";
143+
}
144+
else if (item.ToString() == "Videos")
145+
{
146+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
147+
ContentFrame.Navigate(typeof(GenericFileBrowser), VideosPath);
148+
auto_suggest.PlaceholderText = "Search Videos";
149+
}
150+
else if (item.ToString() == "Local Disk")
151+
{
152+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
153+
ContentFrame.Navigate(typeof(GenericFileBrowser), @"C:\");
154+
auto_suggest.PlaceholderText = "Search";
155+
}
156+
else if (item.ToString() == "OneDrive")
157+
{
158+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
159+
ContentFrame.Navigate(typeof(GenericFileBrowser), OneDrivePath);
160+
auto_suggest.PlaceholderText = "Search OneDrive";
161+
}
146162

163+
}
164+
}
165+
166+
}
147167
public class SelectItem : INotifyPropertyChanged
148168
{
149169

@@ -173,5 +193,6 @@ private void NotifyPropertyChanged(string info)
173193
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
174194
}
175195

176-
}
196+
}
197+
177198
}

0 commit comments

Comments
 (0)