Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Wpfui
提交
90a1a025
W
Wpfui
项目概览
jobily
/
Wpfui
9 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
Wpfui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
90a1a025
编写于
8月 10, 2023
作者:
P
pomianowski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update navigation
上级
6c8b73c2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
13 deletion
+68
-13
src/Wpf.Ui.Extension.Template.Compact/Usings.cs
src/Wpf.Ui.Extension.Template.Compact/Usings.cs
+0
-1
src/Wpf.Ui.Gallery/Usings.cs
src/Wpf.Ui.Gallery/Usings.cs
+0
-1
src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs
...f.Ui/Controls/NavigationView/NavigationView.Navigation.cs
+68
-11
未找到文件。
src/Wpf.Ui.Extension.Template.Compact/Usings.cs
浏览文件 @
90a1a025
...
...
@@ -2,5 +2,4 @@
global
using
System.Windows
;
global
using
CommunityToolkit.Mvvm.ComponentModel
;
global
using
CommunityToolkit.Mvvm.Input
;
global
using
Wpf.Ui.Contracts
;
global
using
Wpf.Ui.Services
;
src/Wpf.Ui.Gallery/Usings.cs
浏览文件 @
90a1a025
...
...
@@ -4,4 +4,3 @@
global
using
Microsoft.Extensions.DependencyInjection
;
global
using
Microsoft.Extensions.Hosting
;
global
using
Wpf.Ui.Common
;
global
using
Wpf.Ui.Contracts
;
src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs
浏览文件 @
90a1a025
// Based on Windows UI Library
// Copyright(c) Microsoft Corporation.All rights reserved.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
...
...
@@ -11,16 +13,17 @@
using
System.Collections.ObjectModel
;
using
System.Diagnostics
;
using
System.Windows
;
using
Wpf.Ui.Contracts
;
namespace
Wpf.Ui.Controls
;
public
partial
class
NavigationView
{
protected
readonly
List
<
string
>
Journal
=
new
(
50
);
protected
readonly
ObservableCollection
<
INavigationViewItem
>
NavigationStack
=
new
();
private
readonly
NavigationCache
_cache
=
new
NavigationCache
();
private
readonly
NavigationCache
_cache
=
new
();
private
readonly
Dictionary
<
INavigationViewItem
,
List
<
INavigationViewItem
?[
]>
...
...
@@ -45,7 +48,9 @@ public partial class NavigationView
public
virtual
bool
Navigate
(
Type
pageType
,
object
?
dataContext
=
null
)
{
if
(!
PageTypeNavigationViewsDictionary
.
TryGetValue
(
pageType
,
out
var
navigationViewItem
))
{
return
TryToNavigateWithoutINavigationViewItem
(
pageType
,
false
,
dataContext
);
}
return
NavigateInternal
(
navigationViewItem
,
dataContext
);
}
...
...
@@ -56,10 +61,12 @@ public virtual bool Navigate(string pageIdOrTargetTag, object? dataContext = nul
if
(
!
PageIdOrTargetTagNavigationViewsDictionary
.
TryGetValue
(
pageIdOrTargetTag
,
out
var
navigationViewItem
out
INavigationViewItem
?
navigationViewItem
)
)
{
return
false
;
}
return
NavigateInternal
(
navigationViewItem
,
dataContext
);
}
...
...
@@ -68,7 +75,9 @@ public virtual bool Navigate(string pageIdOrTargetTag, object? dataContext = nul
public
virtual
bool
NavigateWithHierarchy
(
Type
pageType
,
object
?
dataContext
=
null
)
{
if
(!
PageTypeNavigationViewsDictionary
.
TryGetValue
(
pageType
,
out
var
navigationViewItem
))
{
return
TryToNavigateWithoutINavigationViewItem
(
pageType
,
true
,
dataContext
);
}
return
NavigateInternal
(
navigationViewItem
,
dataContext
,
true
);
}
...
...
@@ -77,7 +86,9 @@ public virtual bool NavigateWithHierarchy(Type pageType, object? dataContext = n
public
virtual
bool
ReplaceContent
(
Type
?
pageTypeToEmbed
)
{
if
(
pageTypeToEmbed
==
null
)
{
return
false
;
}
if
(
_serviceProvider
!=
null
)
{
...
...
@@ -87,7 +98,9 @@ public virtual bool ReplaceContent(Type? pageTypeToEmbed)
}
if
(
_pageService
==
null
)
{
return
false
;
}
UpdateContent
(
_pageService
.
GetPage
(
pageTypeToEmbed
));
...
...
@@ -108,12 +121,16 @@ public virtual bool GoForward()
throw
new
NotImplementedException
();
if
(
Journal
.
Count
<=
1
)
{
return
false
;
}
_currentIndexInJournal
+=
1
;
if
(
_currentIndexInJournal
>
Journal
.
Count
-
1
)
{
return
false
;
}
return
Navigate
(
Journal
[
_currentIndexInJournal
]);
}
...
...
@@ -122,7 +139,9 @@ public virtual bool GoForward()
public
virtual
bool
GoBack
()
{
if
(
Journal
.
Count
<=
1
)
{
return
false
;
}
var
itemId
=
Journal
[^
2
];
...
...
@@ -153,7 +172,9 @@ public virtual void ClearJournal()
var
navigationViewItem
=
new
NavigationViewItem
(
pageType
);
if
(!
NavigateInternal
(
navigationViewItem
,
dataContext
,
addToNavigationStack
))
{
return
false
;
}
PageTypeNavigationViewsDictionary
.
Add
(
pageType
,
navigationViewItem
);
PageIdOrTargetTagNavigationViewsDictionary
.
Add
(
navigationViewItem
.
Id
,
navigationViewItem
);
...
...
@@ -169,20 +190,27 @@ public virtual void ClearJournal()
)
{
if
(
NavigationStack
.
Count
>
0
&&
NavigationStack
[^
1
]
==
viewItem
)
{
return
false
;
}
var
pageInstance
=
GetNavigationItemInstance
(
viewItem
);
if
(
OnNavigating
(
pageInstance
))
{
Debug
.
WriteLineIf
(
EnableDebugMessages
,
"Navigation canceled"
);
#if DEBUG
System
.
Diagnostics
.
Debug
.
WriteLineIf
(
EnableDebugMessages
,
"Navigation canceled"
);
#endif
return
false
;
}
Debug
.
WriteLineIf
(
#if DEBUG
System
.
Diagnostics
.
Debug
.
WriteLineIf
(
EnableDebugMessages
,
$"DEBUG |
{
viewItem
.
Id
}
-
{(
s
tring
.
IsNullOrEmpty
(
viewItem
.
TargetPageTag
)
?
"NO_TAG"
:
viewItem
.
TargetPageTag
)}
-
{
viewItem
.
TargetPageType
}
| NAVIGATED"
$"DEBUG |
{
viewItem
.
Id
}
-
{(
S
tring
.
IsNullOrEmpty
(
viewItem
.
TargetPageTag
)
?
"NO_TAG"
:
viewItem
.
TargetPageTag
)}
-
{
viewItem
.
TargetPageType
}
| NAVIGATED"
);
#endif
OnNavigated
(
pageInstance
);
...
...
@@ -226,7 +254,9 @@ private void AddToJournal(INavigationViewItem viewItem, bool isBackwardsNavigate
private
object
GetNavigationItemInstance
(
INavigationViewItem
viewItem
)
{
if
(
viewItem
.
TargetPageType
is
null
)
{
throw
new
ArgumentNullException
(
nameof
(
viewItem
.
TargetPageType
));
}
if
(
_serviceProvider
is
not
null
)
{
...
...
@@ -270,13 +300,17 @@ private static void ApplyAttachedProperties(INavigationViewItem viewItem, object
pageInstance
is
FrameworkElement
frameworkElement
&&
GetHeaderContent
(
frameworkElement
)
is
{
}
headerContent
)
{
viewItem
.
Content
=
headerContent
;
}
}
private
void
UpdateContent
(
object
?
content
,
object
?
dataContext
=
null
)
{
if
(
dataContext
is
not
null
&&
content
is
FrameworkElement
frameworkViewContent
)
{
frameworkViewContent
.
DataContext
=
dataContext
;
}
NavigationViewContentPresenter
.
Navigate
(
content
);
}
...
...
@@ -287,11 +321,13 @@ System.Windows.Navigation.NavigationEventArgs e
)
{
if
(
sender
is
not
System
.
Windows
.
Controls
.
Frame
frame
)
{
return
;
}
frame
.
RemoveBackEntry
();
_
=
frame
.
RemoveBackEntry
();
var
replaced
=
1
;
//
var replaced = 1;
//((NavigationViewContentPresenter)sender).JournalOwnership =
}
...
...
@@ -304,7 +340,9 @@ bool isBackwardsNavigated
)
{
if
(
isBackwardsNavigated
)
{
RecreateNavigationStackFromHistory
(
viewItem
);
}
if
(
addToNavigationStack
&&
!
NavigationStack
.
Contains
(
viewItem
))
{
...
...
@@ -313,7 +351,9 @@ bool isBackwardsNavigated
}
if
(!
addToNavigationStack
)
{
UpdateCurrentNavigationStackItem
(
viewItem
);
}
ClearNavigationStack
(
viewItem
);
}
...
...
@@ -321,10 +361,14 @@ bool isBackwardsNavigated
private
void
UpdateCurrentNavigationStackItem
(
INavigationViewItem
viewItem
)
{
if
(
NavigationStack
.
Contains
(
viewItem
))
{
return
;
}
if
(
NavigationStack
.
Count
>
1
)
{
AddToNavigationStackHistory
(
viewItem
);
}
if
(
NavigationStack
.
Count
==
0
)
{
...
...
@@ -345,7 +389,9 @@ private void RecreateNavigationStackFromHistory(INavigationViewItem item)
!
_complexNavigationStackHistory
.
TryGetValue
(
item
,
out
var
historyList
)
||
historyList
.
Count
==
0
)
{
return
;
}
var
latestHistory
=
historyList
[^
1
];
var
startIndex
=
0
;
...
...
@@ -359,7 +405,9 @@ private void RecreateNavigationStackFromHistory(INavigationViewItem item)
for
(
int
i
=
startIndex
;
i
<
latestHistory
.
Length
;
i
++)
{
if
(
latestHistory
[
i
]
is
null
)
{
break
;
}
AddToNavigationStack
(
latestHistory
[
i
]!,
true
,
false
);
}
...
...
@@ -382,7 +430,9 @@ private void AddToNavigationStackHistory(INavigationViewItem viewItem)
var
startIndex
=
NavigationStack
.
IndexOf
(
viewItem
);
if
(
startIndex
<
0
)
{
startIndex
=
0
;
}
if
(!
_complexNavigationStackHistory
.
TryGetValue
(
lastItem
,
out
var
historyList
))
{
...
...
@@ -402,9 +452,10 @@ private void AddToNavigationStackHistory(INavigationViewItem viewItem)
#endif
historyList
.
Add
(
array
);
var
latestHistory
=
historyList
[^
1
];
var
latestHistory
=
historyList
[^
1
];
int
i
=
0
;
for
(
int
j
=
startIndex
;
j
<
NavigationStack
.
Count
-
1
;
j
++)
{
latestHistory
[
i
]
=
NavigationStack
[
j
];
...
...
@@ -418,7 +469,9 @@ private void ClearNavigationStack(int navigationStackItemIndex)
var
length
=
navigationStackCount
-
navigationStackItemIndex
;
if
(
length
==
0
)
{
return
;
}
for
(
int
j
=
navigationStackCount
-
1
;
j
>=
navigationStackCount
-
length
;
j
--)
{
...
...
@@ -430,11 +483,15 @@ private void ClearNavigationStack(INavigationViewItem item)
{
var
navigationStackCount
=
NavigationStack
.
Count
;
if
(
navigationStackCount
<=
1
)
{
return
;
}
var
index
=
NavigationStack
.
IndexOf
(
item
);
if
(
index
>=
navigationStackCount
-
1
)
{
return
;
}
AddToNavigationStackHistory
(
item
);
ClearNavigationStack
(++
index
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录