Skip to content

Commit e5d68ec

Browse files
committed
Improve JsonNavigationService
1 parent 1dba625 commit e5d68ec

5 files changed

Lines changed: 29 additions & 65 deletions

File tree

dev/DevWinUI/Common/BreadcrumbNavigator/BreadcrumbNavigator.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,15 @@ internal void AddNewItem(Type targetPageType, NavigationTransitionInfo navigatio
238238
{
239239
pageTitle = pageTitleAttached;
240240
}
241-
else
241+
else if (currentPageParameter != null)
242242
{
243-
if (currentPageParameter != null && currentPageParameter is string value)
243+
if (currentPageParameter is string value)
244244
{
245245
pageTitle = value;
246246
}
247-
else if (currentPageParameter != null && currentPageParameter is DataItem dataItem)
248-
{
249-
pageTitle = dataItem.Title;
250-
}
251-
else if (currentPageParameter != null && currentPageParameter is DataGroup dataGroup)
247+
else if (currentPageParameter is BaseDataInfo dataInfo)
252248
{
253-
pageTitle = dataGroup.Title;
249+
pageTitle = dataInfo.Title;
254250
}
255251
}
256252

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
namespace DevWinUI;
22
public partial class BaseDataInfo
33
{
4+
public string UniqueId { get; set; }
5+
public string SectionId { get; set; }
6+
public string Title { get; set; }
7+
public string ApiNamespace { get; set; }
8+
public string SecondaryTitle { get; set; }
9+
public string Subtitle { get; set; }
10+
public string Description { get; set; }
11+
public string ImagePath { get; set; }
12+
public string IconGlyph { get; set; }
13+
public bool IsNavigationViewItemHeader { get; set; }
14+
public bool UsexUid { get; set; }
415
public DataInfoBadge DataInfoBadge { get; set; }
516
}

dev/DevWinUI/Services/NavigationService/Models/DataGroup.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,11 @@ namespace DevWinUI;
44

55
public partial class DataGroup : BaseDataInfo
66
{
7-
public string UniqueId { get; set; }
8-
public string SectionId { get; set; }
9-
public string ApiNamespace { get; set; }
10-
public string Title { get; set; }
11-
public string SecondaryTitle { get; set; }
12-
public string Subtitle { get; set; }
13-
public string Description { get; set; }
14-
public string ImagePath { get; set; }
15-
public string IconGlyph { get; set; }
167
public bool IsSpecialSection { get; set; }
178
public bool IsExpanded { get; set; }
189
public bool HideGroup { get; set; }
1910
public bool ShowItemsWithoutGroup { get; set; }
2011
public bool IsFooterNavigationViewItem { get; set; }
21-
public bool IsNavigationViewItemHeader { get; set; }
22-
public bool UsexUid { get; set; }
2312
public bool Order { get; set; }
2413
public bool OrderByDescending { get; set; }
2514
public ObservableCollection<DataItem> Items { get; set; } = new();

dev/DevWinUI/Services/NavigationService/Models/DataItem.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ namespace DevWinUI;
44

55
public partial class DataItem : BaseDataInfo
66
{
7-
public string UniqueId { get; set; }
8-
public string SectionId { get; set; }
9-
public string Title { get; set; }
10-
public string SecondaryTitle { get; set; }
117
public object Parameter { get; set; }
12-
public string ApiNamespace { get; set; }
13-
public string Subtitle { get; set; }
14-
public string Description { get; set; }
15-
public string ImagePath { get; set; }
16-
public string IconGlyph { get; set; }
178
public string BadgeString { get; set; }
189
public string Content { get; set; }
1910
public bool IsNew { get; set; }
@@ -24,10 +15,8 @@ public partial class DataItem : BaseDataInfo
2415
public ObservableCollection<DataLink> Links { get; set; }
2516
public ObservableCollection<string> Extra { get; set; }
2617
public bool IncludedInBuild { get; set; } = true;
27-
public bool IsNavigationViewItemHeader { get; set; }
28-
public bool UsexUid { get; set; }
2918
public override string ToString()
3019
{
3120
return Title;
3221
}
33-
}
22+
}

dev/DevWinUI/Services/NavigationService/Services/JsonNavigationService/JsonNavigationService.cs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,13 @@ private void OnNavigated(object sender, NavigationEventArgs e)
4848
return;
4949
}
5050

51-
if (e.Parameter is DataItem dataItem)
51+
if (e.Parameter is BaseDataInfo dataInfo)
5252
{
53-
if (!string.IsNullOrEmpty(dataItem.UniqueId))
53+
if (!string.IsNullOrEmpty(dataInfo.UniqueId))
5454
{
55-
if (e.NavigationMode == NavigationMode.Back || !currentTag.Equals(dataItem.UniqueId))
55+
if (e.NavigationMode == NavigationMode.Back || !currentTag.Equals(dataInfo.UniqueId))
5656
{
57-
EnsureNavigationSelection(dataItem.UniqueId);
58-
}
59-
}
60-
}
61-
else if (e.Parameter is DataGroup dataGroup)
62-
{
63-
if (!string.IsNullOrEmpty(dataGroup.UniqueId))
64-
{
65-
if (e.NavigationMode == NavigationMode.Back || !currentTag.Equals(dataGroup.UniqueId))
66-
{
67-
EnsureNavigationSelection(dataGroup.UniqueId);
57+
EnsureNavigationSelection(dataInfo.UniqueId);
6858
}
6959
}
7060
}
@@ -91,36 +81,25 @@ private void OnSelectionChanged(NavigationView sender, NavigationViewSelectionCh
9181
{
9282
if (args.IsSettingsSelected)
9383
{
94-
if (GetPageType(SettingsPageKey) != null)
84+
string pageTitle = string.Empty;
85+
var item = SettingsItem as NavigationViewItem;
86+
if (item != null && item.Content != null)
9587
{
96-
string pageTitle = string.Empty;
97-
var item = SettingsItem as NavigationViewItem;
98-
if (item != null && item.Content != null)
99-
{
100-
pageTitle = item.Content?.ToString();
101-
}
102-
NavigateTo(SettingsPageKey, pageTitle);
88+
pageTitle = item.Content?.ToString();
10389
}
90+
NavigateTo(SettingsPageKey, pageTitle);
10491
}
10592
else
10693
{
10794
var selectedItem = args.SelectedItemContainer as NavigationViewItem;
108-
109-
if (_sectionPage != null && selectedItem.DataContext is DataGroup itemGroup && !string.IsNullOrEmpty(itemGroup.SectionId))
110-
{
111-
NavigateTo(SectionPageKey, itemGroup);
112-
}
113-
else if (_sectionPage != null && selectedItem.DataContext is DataItem item && !string.IsNullOrEmpty(item.SectionId))
95+
var dataInfo = selectedItem.DataContext as BaseDataInfo;
96+
if (_sectionPage != null && !string.IsNullOrEmpty(dataInfo?.SectionId))
11497
{
115-
NavigateTo(SectionPageKey, item);
98+
NavigateTo(SectionPageKey, dataInfo);
11699
}
117100
else
118101
{
119-
if (selectedItem?.GetValue(NavigationHelperEx.NavigateToProperty) is string pageKey)
120-
{
121-
var dataItem = selectedItem?.DataContext as DataItem;
122-
NavigateTo(pageKey, dataItem);
123-
}
102+
NavigateTo(dataInfo?.UniqueId, dataInfo);
124103
}
125104
}
126105
}

0 commit comments

Comments
 (0)