Skip to content

Commit 51d1622

Browse files
committed
Adds NavigationProperties.
1 parent 716d922 commit 51d1622

12 files changed

+158
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ https://user-images.githubusercontent.com/901816/211709015-77fee141-17b7-45e6-a9
1818
- **SettingsCard** - Provide basic settings card.
1919
- **SettingsExpander** - Provide settings card with expander.
2020
- **SettingsPanel** - Provide settings layout in items control, such as `ListView` or `GridView`, with the style `CardListViewItemStyle`.
21+
- *Mntone.AngelUmbrella.Navigation*
22+
- **NavigationProperties** - Provide xaml-friendly navigation data.
2123

2224
## Requirements
2325

idl/AngelUmbrella.idl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,28 @@ namespace Mntone.AngelUmbrella
165165
SettingsCardAutomationPeer(Mntone.AngelUmbrella.Controls.SettingsCard owner);
166166
}
167167
}
168+
169+
namespace Navigation
170+
{
171+
172+
[static_name("INavigationPropertiesStatics", 514F7EE7-3A01-51CD-AA81-C320C329FCDC)]
173+
static runtimeclass NavigationProperties
174+
{
175+
static void Initialize();
176+
177+
static Windows.UI.Xaml.Interop.TypeName GetPageType(Microsoft.UI.Xaml.Controls.NavigationViewItem item);
178+
static void SetPageType(Microsoft.UI.Xaml.Controls.NavigationViewItem item, Windows.UI.Xaml.Interop.TypeName value);
179+
180+
static Object GetParameter(Microsoft.UI.Xaml.Controls.NavigationViewItem item);
181+
static void SetParameter(Microsoft.UI.Xaml.Controls.NavigationViewItem item, Object value);
182+
183+
static Microsoft.UI.Xaml.Media.Animation.NavigationTransitionInfo GetTransitionInfo(Microsoft.UI.Xaml.Controls.NavigationViewItem item);
184+
static void SetTransitionInfo(Microsoft.UI.Xaml.Controls.NavigationViewItem item, Microsoft.UI.Xaml.Media.Animation.NavigationTransitionInfo value);
185+
186+
[noexcept] static Microsoft.UI.Xaml.DependencyProperty PageTypeProperty { get; };
187+
[noexcept] static Microsoft.UI.Xaml.DependencyProperty ParameterProperty { get; };
188+
[noexcept] static Microsoft.UI.Xaml.DependencyProperty TransitionInfoProperty { get; };
189+
}
190+
191+
}
168192
}

samples/App.xaml.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ namespace winrt {
1313
using namespace winrt::Mntone::AngelUmbrella::Samples::implementation;
1414

1515
App::App() {
16+
// Require vvv HERE vvv to use NavigationProperties.
17+
Navigation::NavigationProperties::Initialize();
18+
1619
InitializeComponent();
1720

1821
#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION

samples/App.xaml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include "App.xaml.g.h"
33
#include <winrt/Mntone.AngelUmbrella.Converters.h>
4+
#include <winrt/Mntone.AngelUmbrella.Navigation.h>
45

56
namespace winrt::Mntone::AngelUmbrella::Samples::implementation {
67

samples/SettingsWindow.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Window x:Class="Mntone.AngelUmbrella.Samples.SettingsWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="using:Mntone.AngelUmbrella.Samples"
5+
xmlns:nav="using:Mntone.AngelUmbrella.Navigation"
46
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
57
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
68
mc:Ignorable="d">
@@ -36,14 +38,16 @@
3638
Color="Transparent" />
3739
</NavigationView.Resources>
3840
<NavigationView.MenuItems>
39-
<NavigationViewItem Content="RootPage">
41+
<NavigationViewItem Content="RootPage"
42+
nav:NavigationProperties.PageType="local:SettingsWindow_RootPage">
4043
<NavigationViewItem.Icon>
4144
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}"
4245
FontSize="12"
4346
Glyph="&#xE71D;" />
4447
</NavigationViewItem.Icon>
4548
</NavigationViewItem>
46-
<NavigationViewItem Content="OddEvenPage">
49+
<NavigationViewItem Content="OddEvenPage"
50+
nav:NavigationProperties.PageType="local:SettingsWindow_OddEvenPage">
4751
<NavigationViewItem.Icon>
4852
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}"
4953
FontSize="12"

samples/SettingsWindow.xaml.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <microsoft.ui.xaml.window.h>
88
#include <winrt/Microsoft.UI.Interop.h>
99
#include <winrt/Microsoft.UI.Windowing.h>
10+
#include <winrt/Mntone.AngelUmbrella.Navigation.h>
1011

1112
#include "SettingsWindow_RootPage.xaml.h"
1213
#include "SettingsWindow_OddEvenPage.xaml.h"
@@ -20,6 +21,7 @@ namespace winrt {
2021
using namespace ::winrt::Windows::Globalization;
2122
using namespace ::winrt::Windows::System;
2223
using namespace ::winrt::Windows::UI::Core;
24+
using namespace ::winrt::Windows::UI::Xaml::Interop;
2325

2426
using namespace ::winrt::Microsoft::UI;
2527
using namespace ::winrt::Microsoft::UI::Input;
@@ -29,6 +31,7 @@ namespace winrt {
2931
using namespace ::winrt::Microsoft::UI::Xaml::Input;
3032
using namespace ::winrt::Microsoft::UI::Xaml::Media::Animation;
3133

34+
using namespace ::winrt::Mntone::AngelUmbrella::Navigation;
3235
using namespace ::winrt::Mntone::AngelUmbrella::Samples;
3336
}
3437

@@ -73,15 +76,10 @@ SettingsWindow::SettingsWindow() {
7376
}
7477

7578
void SettingsWindow::NavigationViewSelectionChanged(NavigationView const& /*sender*/, NavigationViewSelectionChangedEventArgs const& args) {
76-
using namespace std::string_view_literals;
77-
78-
std::optional<hstring> name { args.SelectedItem().as<NavigationViewItem>().Content().try_as<hstring>() };
79+
NavigationViewItem item { args.SelectedItem().as<NavigationViewItem>() };
7980
Frame frame { rootFrame() };
80-
if (name && L"OddEvenPage"sv == name.value()) {
81-
frame.Navigate(xaml_typename<winrt::SettingsWindow_OddEvenPage>());
82-
} else {
83-
frame.Navigate(xaml_typename<winrt::SettingsWindow_RootPage>());
84-
}
81+
TypeName pageTypeName { NavigationProperties::GetPageType(item) }; // Require NavigationProperties::Initialize() (Check App.xaml.h)
82+
frame.Navigate(pageTypeName);
8583
}
8684

8785
void SettingsWindow::OnPointerPressed(IInspectable const& /*sender*/, PointerRoutedEventArgs const& args) {

src/AngelUmbrella.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<ClInclude Include="Helpers\DependencyPropertyHelper.h" />
176176
<ClInclude Include="Helpers\ValueHelper.h" />
177177
<ClInclude Include="Helpers\XamlHelpers.h" />
178+
<ClInclude Include="Navigation\NavigationProperties.h" />
178179
</ItemGroup>
179180
<ItemGroup>
180181
<ClCompile Include="pch.cpp">
@@ -207,6 +208,7 @@
207208
<ClCompile Include="Converters\InvertedBooleanConverter.cpp" />
208209
<ClCompile Include="Converters\StringIsPresentToVisibilityConverter.cpp" />
209210
<ClCompile Include="Helpers\XamlHelpers.cpp" />
211+
<ClCompile Include="Navigation\NavigationProperties.cpp" />
210212
</ItemGroup>
211213
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
212214
<ImportGroup Label="ExtensionTargets">

src/AngelUmbrella.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<Filter Include="Helpers">
2020
<UniqueIdentifier>{e4cfde82-f621-42f3-aa13-dad288a8f072}</UniqueIdentifier>
2121
</Filter>
22+
<Filter Include="Navigation">
23+
<UniqueIdentifier>{e1cda238-ec8f-448f-8e41-39c6a107cb1b}</UniqueIdentifier>
24+
</Filter>
2225
</ItemGroup>
2326
<ItemGroup>
2427
<None Include="AngelUmbrella.def" />
@@ -76,6 +79,9 @@
7679
<ClInclude Include="Helpers\XamlHelpers.h">
7780
<Filter>Helpers</Filter>
7881
</ClInclude>
82+
<ClInclude Include="Navigation\NavigationProperties.h">
83+
<Filter>Navigation</Filter>
84+
</ClInclude>
7985
</ItemGroup>
8086
<ItemGroup>
8187
<ClCompile Include="pch.cpp" />
@@ -104,5 +110,8 @@
104110
<ClCompile Include="Helpers\XamlHelpers.cpp">
105111
<Filter>Helpers</Filter>
106112
</ClCompile>
113+
<ClCompile Include="Navigation\NavigationProperties.cpp">
114+
<Filter>Navigation</Filter>
115+
</ClCompile>
107116
</ItemGroup>
108117
</Project>

src/Helpers/DependencyPropertyHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace winrt {
3232
#endif
3333

3434
#define DEFINE_DP(__PROPNAME__, __TYPE__, __PARENT_TYPE__) \
35-
DEFINE_DP_METADATA(__PROPNAME__, __TYPE__, __PARENT_TYPE__, ::winrt::PropertyMetadata(::winrt::Mntone::AngelUmbrella::Helpers::ValueHelper<__TYPE__>::DefaultValue()))
35+
DEFINE_DP_METADATA(__PROPNAME__, __TYPE__, __PARENT_TYPE__, nullptr)
3636

3737
#define DEFINE_DP_CALLBACK(__PROPNAME__, __TYPE__, __PARENT_TYPE__, __CALLBACK__) \
3838
DEFINE_DP_METADATA(__PROPNAME__, __TYPE__, __PARENT_TYPE__, \
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "pch.h"
2+
#include "NavigationProperties.h"
3+
#if __has_include("./Navigation/NavigationProperties.g.cpp")
4+
#include "./Navigation/NavigationProperties.g.cpp"
5+
#endif
6+
7+
#define DELAY_INIT_DP // Delay Init
8+
#include "Helpers/DependencyPropertyHelper.h"
9+
10+
namespace projection { // Need to build
11+
using namespace ::winrt::Mntone::AngelUmbrella::Navigation;
12+
}
13+
14+
using namespace ::winrt::Mntone::AngelUmbrella::Navigation::implementation;
15+
16+
NavigationProperties::DependencyProperties NavigationProperties::props_;
17+
18+
void NavigationProperties::DependencyProperties::DelayInitIfNeeded() {
19+
if (initialized_) return;
20+
21+
DEFINE_PARENT_TYPENAME(NavigationProperties);
22+
23+
DEFINE_DP(
24+
PageType,
25+
Windows::UI::Xaml::Interop::TypeName,
26+
NavigationProperties);
27+
28+
DEFINE_DP(
29+
Parameter,
30+
Windows::Foundation::IInspectable,
31+
NavigationProperties);
32+
33+
DEFINE_DP(
34+
TransitionInfo,
35+
Microsoft::UI::Xaml::Media::Animation::NavigationTransitionInfo,
36+
NavigationProperties);
37+
38+
initialized_ = true;
39+
}

src/Navigation/NavigationProperties.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#pragma once
2+
#include "Navigation/NavigationProperties.g.h"
3+
4+
namespace winrt::Mntone::AngelUmbrella::Navigation::implementation {
5+
6+
struct NavigationProperties final {
7+
static inline void Initialize() {
8+
props_.DelayInitIfNeeded();
9+
}
10+
11+
static inline Windows::UI::Xaml::Interop::TypeName GetPageType(Microsoft::UI::Xaml::Controls::NavigationViewItem const& item) {
12+
return unbox_value<Windows::UI::Xaml::Interop::TypeName>(item.GetValue(props_.PageType));
13+
}
14+
15+
static inline void SetPageType(
16+
Microsoft::UI::Xaml::Controls::NavigationViewItem const& item,
17+
Windows::UI::Xaml::Interop::TypeName const& value) {
18+
item.SetValue(props_.PageType, box_value(value));
19+
}
20+
21+
static inline Windows::Foundation::IInspectable GetParameter(Microsoft::UI::Xaml::Controls::NavigationViewItem const& item) {
22+
return item.GetValue(props_.Parameter);
23+
}
24+
25+
static inline void SetParameter(
26+
Microsoft::UI::Xaml::Controls::NavigationViewItem const& item,
27+
Windows::Foundation::IInspectable const& value) {
28+
item.SetValue(props_.Parameter, value);
29+
}
30+
31+
static inline Microsoft::UI::Xaml::Media::Animation::NavigationTransitionInfo GetTransitionInfo(Microsoft::UI::Xaml::Controls::NavigationViewItem const& item) {
32+
return unbox_value<Microsoft::UI::Xaml::Media::Animation::NavigationTransitionInfo>(item.GetValue(props_.TransitionInfo));
33+
}
34+
35+
static inline void SetTransitionInfo(
36+
Microsoft::UI::Xaml::Controls::NavigationViewItem const& item,
37+
Microsoft::UI::Xaml::Media::Animation::NavigationTransitionInfo const& value) {
38+
item.SetValue(props_.TransitionInfo, value);
39+
}
40+
41+
static winrt::Microsoft::UI::Xaml::DependencyProperty PageTypeProperty() noexcept { return props_.PageType; }
42+
static winrt::Microsoft::UI::Xaml::DependencyProperty ParameterProperty() noexcept { return props_.Parameter; }
43+
static winrt::Microsoft::UI::Xaml::DependencyProperty TransitionInfoProperty() noexcept { return props_.TransitionInfo; }
44+
45+
private:
46+
struct DependencyProperties final {
47+
void DelayInitIfNeeded();
48+
49+
bool initialized_ { false };
50+
Microsoft::UI::Xaml::DependencyProperty PageType { nullptr };
51+
Microsoft::UI::Xaml::DependencyProperty Parameter { nullptr };
52+
Microsoft::UI::Xaml::DependencyProperty TransitionInfo { nullptr };
53+
};
54+
static DependencyProperties props_;
55+
};
56+
57+
}
58+
59+
namespace winrt::Mntone::AngelUmbrella::Navigation::factory_implementation {
60+
61+
struct NavigationProperties: NavigationPropertiesT<NavigationProperties, implementation::NavigationProperties> {
62+
};
63+
64+
}

src/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<AngelCopyright>Copyright (c) 2023 $(AngelAuthor). All rights reserved.</AngelCopyright>
66
<AngelVersionMajor>1</AngelVersionMajor>
77
<AngelVersionMinor>1</AngelVersionMinor>
8-
<AngelVersionPatch>0</AngelVersionPatch>
8+
<AngelVersionPatch>1</AngelVersionPatch>
99
<AngelVersionBuild Condition="$(AngelVersionBuild)==''">$([System.DateTime]::Now.ToString(`yyyy`))</AngelVersionBuild>
1010
<AngelVersionRevision Condition="$(AngelVersionRevision)==''">$([System.DateTime]::Now.ToString(`MMdd`))</AngelVersionRevision>
1111
<AngelVersionPreRelease></AngelVersionPreRelease>

0 commit comments

Comments
 (0)