Skip to content

Commit 134c8b4

Browse files
committed
Update JsonNavigationService.cs
1 parent 43dc6ad commit 134c8b4

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@ private void OnNavigated(object sender, NavigationEventArgs e)
4141
}
4242
else
4343
{
44-
var currentItem = (NavigationViewItem)_navigationView.SelectedItem;
45-
var currentTag = currentItem?.Tag?.ToString();
46-
if (string.IsNullOrEmpty(currentTag))
47-
{
48-
return;
49-
}
50-
51-
if (e.Parameter is BaseDataInfo dataInfo && dataInfo != null)
44+
if (_navigationView.SelectedItem is NavigationViewItem currentItem && currentItem.Tag is string currentTag && !string.IsNullOrEmpty(currentTag) && e.Parameter is BaseDataInfo dataInfo)
5245
{
5346
if (e.NavigationMode == NavigationMode.Back || !currentTag.Equals(dataInfo.UniqueId))
5447
{
@@ -88,15 +81,13 @@ private void OnSelectionChanged(NavigationView sender, NavigationViewSelectionCh
8881
}
8982
else
9083
{
91-
var selectedItem = args.SelectedItemContainer as NavigationViewItem;
92-
var dataInfo = selectedItem.DataContext as BaseDataInfo;
93-
if (_sectionPage != null && !string.IsNullOrEmpty(dataInfo?.SectionId))
84+
if (args.SelectedItemContainer is NavigationViewItem selectedItem && selectedItem.DataContext is BaseDataInfo dataInfo)
9485
{
95-
NavigateTo(SectionPageKey, dataInfo);
96-
}
97-
else
98-
{
99-
NavigateTo(dataInfo?.UniqueId, dataInfo);
86+
var targetKey = !string.IsNullOrEmpty(dataInfo.SectionId) && _sectionPage != null
87+
? SectionPageKey
88+
: dataInfo.UniqueId;
89+
90+
NavigateTo(targetKey, dataInfo);
10091
}
10192
}
10293
}

0 commit comments

Comments
 (0)