Skip to content

Commit 838cd35

Browse files
committed
Extend navigation aware pages with INavigableView<T> interface
1 parent a792c0c commit 838cd35

21 files changed

+245
-170
lines changed

src/Wpf.Ui.Demo/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public partial class App
6969

7070
// Views and ViewModels
7171
services.AddScoped<Views.Pages.Dashboard>();
72+
services.AddScoped<DashboardViewModel>();
7273

7374
services.AddScoped<Views.Pages.ExperimentalDashboard>();
7475
services.AddScoped<ExperimentalViewModel>();

src/Wpf.Ui.Demo/ViewModels/ButtonsViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class ButtonsViewModel : Wpf.Ui.Mvvm.ViewModelBase
1313
public ButtonsViewModel(INavigationService navigationService)
1414
{
1515
_navigationService = navigationService;
16+
17+
var testGetThemeService = App.GetService<IThemeService>();
18+
var currentTheme = testGetThemeService.GetSystemTheme();
1619
}
1720

1821
protected override void OnViewCommand(object parameter = null)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// This Source Code Form is subject to the terms of the MIT License.
2+
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
3+
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
4+
// All Rights Reserved.
5+
6+
using Wpf.Ui.Common.Interfaces;
7+
using Wpf.Ui.Demo.Services.Contracts;
8+
using Wpf.Ui.Mvvm.Contracts;
9+
10+
namespace Wpf.Ui.Demo.ViewModels;
11+
12+
public class DashboardViewModel : Wpf.Ui.Mvvm.ViewModelBase, INavigationAware
13+
{
14+
private readonly INavigationService _navigationService;
15+
16+
private readonly ITestWindowService _testWindowService;
17+
18+
public DashboardViewModel(INavigationService navigationService, ITestWindowService testWindowService)
19+
{
20+
_navigationService = navigationService;
21+
_testWindowService = testWindowService;
22+
}
23+
24+
protected override void OnViewCommand(object parameter = null)
25+
{
26+
if (parameter is not string parameterString)
27+
return;
28+
29+
if (parameterString.StartsWith("navigate_to"))
30+
OnNavigateCommand(parameterString);
31+
32+
if (parameterString.StartsWith("open_window"))
33+
OnOpenWindowCommand(parameterString);
34+
}
35+
36+
public void OnNavigatedTo()
37+
{
38+
System.Diagnostics.Debug.WriteLine($"INFO | {typeof(DashboardViewModel)} navigated", "Wpf.Ui.Demo");
39+
}
40+
41+
public void OnNavigatedFrom()
42+
{
43+
System.Diagnostics.Debug.WriteLine($"INFO | {typeof(DashboardViewModel)} navigated", "Wpf.Ui.Demo");
44+
}
45+
46+
private void OnNavigateCommand(string parameter)
47+
{
48+
switch (parameter)
49+
{
50+
case "navigate_to_input":
51+
_navigationService.Navigate(typeof(Views.Pages.Input));
52+
return;
53+
54+
case "navigate_to_controls":
55+
_navigationService.Navigate(typeof(Views.Pages.Controls));
56+
return;
57+
58+
case "navigate_to_colors":
59+
_navigationService.Navigate(typeof(Views.Pages.Colors));
60+
return;
61+
62+
case "navigate_to_icons":
63+
_navigationService.Navigate(typeof(Views.Pages.Icons));
64+
return;
65+
}
66+
}
67+
68+
private void OnOpenWindowCommand(string parameter)
69+
{
70+
switch (parameter)
71+
{
72+
case "open_window_store":
73+
_testWindowService.Show<Views.Windows.StoreWindow>();
74+
return;
75+
76+
case "open_window_manager":
77+
_testWindowService.Show<Views.Windows.TaskManagerWindow>();
78+
return;
79+
80+
case "open_window_editor":
81+
_testWindowService.Show<Views.Windows.EditorWindow>();
82+
return;
83+
84+
case "open_window_settings":
85+
_testWindowService.Show<Views.Windows.SettingsWindow>();
86+
return;
87+
88+
case "open_window_experimental":
89+
_testWindowService.Show<Views.Windows.ExperimentalWindow>();
90+
return;
91+
}
92+
}
93+
}
94+

src/Wpf.Ui.Demo/Views/Pages/Buttons.xaml.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
44
// All Rights Reserved.
55

6+
using Wpf.Ui.Common.Interfaces;
67
using Wpf.Ui.Demo.ViewModels;
7-
using Wpf.Ui.Mvvm.Contracts;
88

99
namespace Wpf.Ui.Demo.Views.Pages;
1010

1111
/// <summary>
1212
/// Interaction logic for Buttons.xaml
1313
/// </summary>
14-
public partial class Buttons
14+
public partial class Buttons : INavigableView<ButtonsViewModel>
1515
{
1616
public ButtonsViewModel ViewModel
1717
{
@@ -20,12 +20,7 @@ public ButtonsViewModel ViewModel
2020

2121
public Buttons(ButtonsViewModel viewModel)
2222
{
23-
//ViewModel = App.GetService<ButtonsViewModel>();
2423
ViewModel = viewModel;
25-
DataContext = this;
26-
27-
var testGetThemeService = App.GetService<IThemeService>();
28-
var currentTheme = testGetThemeService.GetSystemTheme();
2924

3025
InitializeComponent();
3126
}

src/Wpf.Ui.Demo/Views/Pages/Colors.xaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:local="clr-namespace:Wpf.Ui.Demo.Views.Pages"
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9-
xmlns:pages="clr-namespace:Wpf.Ui.Demo.Views.Pages"
10-
xmlns:viewModels="clr-namespace:Wpf.Ui.Demo.ViewModels"
119
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
1210
Title="Colors"
13-
d:DataContext="{d:DesignInstance viewModels:ColorsViewModel,
11+
d:DataContext="{d:DesignInstance local:Colors,
1412
IsDesignTimeCreatable=False}"
1513
d:DesignHeight="450"
1614
d:DesignWidth="800"
@@ -37,10 +35,10 @@
3735
<ItemsControl
3836
Grid.Row="0"
3937
Margin="-4,0,-4,0"
40-
ItemsSource="{Binding PaletteBrushes, Mode=OneWay}">
38+
ItemsSource="{Binding ViewModel.PaletteBrushes, Mode=OneWay}">
4139
<ItemsControl.ItemsPanel>
4240
<ItemsPanelTemplate>
43-
<UniformGrid Columns="{Binding Columns, Mode=OneWay}" />
41+
<UniformGrid Columns="{Binding ViewModel.Columns, Mode=OneWay}" />
4442
</ItemsPanelTemplate>
4543
</ItemsControl.ItemsPanel>
4644
<ItemsControl.ItemTemplate>
@@ -66,10 +64,10 @@
6664
<ItemsControl
6765
Grid.Row="2"
6866
Margin="-4,0,-4,0"
69-
ItemsSource="{Binding ThemeBrushes, Mode=OneWay}">
67+
ItemsSource="{Binding ViewModel.ThemeBrushes, Mode=OneWay}">
7068
<ItemsControl.ItemsPanel>
7169
<ItemsPanelTemplate>
72-
<UniformGrid Columns="{Binding Columns, Mode=OneWay}" />
70+
<UniformGrid Columns="{Binding ViewModel.Columns, Mode=OneWay}" />
7371
</ItemsPanelTemplate>
7472
</ItemsControl.ItemsPanel>
7573
<ItemsControl.ItemTemplate>

src/Wpf.Ui.Demo/Views/Pages/Colors.xaml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
44
// All Rights Reserved.
55

6+
using Wpf.Ui.Common.Interfaces;
67
using Wpf.Ui.Demo.ViewModels;
78

89
namespace Wpf.Ui.Demo.Views.Pages;
910

1011
/// <summary>
1112
/// Interaction logic for Colors.xaml
1213
/// </summary>
13-
public partial class Colors
14+
public partial class Colors : INavigableView<ColorsViewModel>
1415
{
16+
public ColorsViewModel ViewModel
17+
{
18+
get;
19+
}
20+
1521
public Colors(ColorsViewModel viewModel)
1622
{
17-
DataContext = viewModel;
23+
ViewModel = viewModel;
24+
1825
InitializeComponent();
1926
}
2027
}

src/Wpf.Ui.Demo/Views/Pages/Controls.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
Title="Controls"
1010
d:DesignHeight="1750"
1111
d:DesignWidth="800"
12-
Loaded="Controls_OnLoaded"
12+
Loaded="OnLoaded"
1313
Scrollable="True"
14-
Unloaded="Controls_OnUnloaded"
14+
Unloaded="OnUnloaded"
1515
mc:Ignorable="d">
1616

1717
<VirtualizingStackPanel

src/Wpf.Ui.Demo/Views/Pages/Controls.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public Controls(ISnackbarService snackbarService, IDialogService dialogService)
2828
_dialogControl = dialogService.GetDialogControl();
2929
}
3030

31-
private void Controls_OnLoaded(object sender, RoutedEventArgs e)
31+
private void OnLoaded(object sender, RoutedEventArgs e)
3232
{
3333
RootPanel.ScrollOwner = ScrollHost;
3434

3535
_dialogControl.ButtonRightClick += DialogControlOnButtonRightClick;
3636
}
3737

38-
private void Controls_OnUnloaded(object sender, RoutedEventArgs e)
38+
private void OnUnloaded(object sender, RoutedEventArgs e)
3939
{
4040
_dialogControl.ButtonRightClick -= DialogControlOnButtonRightClick;
4141
}

src/Wpf.Ui.Demo/Views/Pages/Dashboard.xaml

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
99
Title="Dashboard"
10+
d:DataContext="{d:DesignInstance local:Dashboard,
11+
IsDesignTimeCreatable=False}"
1012
d:DesignHeight="750"
1113
d:DesignWidth="800"
1214
Scrollable="True"
@@ -61,7 +63,8 @@
6163
Padding="30,6"
6264
HorizontalAlignment="Left"
6365
Appearance="Transparent"
64-
Click="ButtonControls_OnClick"
66+
Command="{Binding ViewModel.ViewCommand}"
67+
CommandParameter="navigate_to_controls"
6568
Content="Check out the controls"
6669
Foreground="{DynamicResource TextFillColorLightPrimaryBrush}" />
6770
</StackPanel>
@@ -92,9 +95,9 @@
9295
Grid.Row="0"
9396
Grid.Column="0"
9497
Margin="0,0,4,0"
95-
Click="ButtonAction_OnClick"
96-
Icon="TextParagraph24"
97-
Tag="input">
98+
Command="{Binding ViewModel.ViewCommand}"
99+
CommandParameter="navigate_to_input"
100+
Icon="TextParagraph24">
98101
<StackPanel>
99102
<TextBlock
100103
Margin="0"
@@ -112,9 +115,9 @@
112115
Grid.Row="0"
113116
Grid.Column="1"
114117
Margin="4,0,4,0"
115-
Click="ButtonAction_OnClick"
116-
Icon="Fluent24"
117-
Tag="controls">
118+
Command="{Binding ViewModel.ViewCommand}"
119+
CommandParameter="navigate_to_controls"
120+
Icon="Fluent24">
118121
<StackPanel>
119122
<TextBlock
120123
Margin="0"
@@ -132,9 +135,9 @@
132135
Grid.Row="0"
133136
Grid.Column="2"
134137
Margin="4,0,4,0"
135-
Click="ButtonAction_OnClick"
136-
Icon="Color16"
137-
Tag="colors">
138+
Command="{Binding ViewModel.ViewCommand}"
139+
CommandParameter="navigate_to_colors"
140+
Icon="Color16">
138141
<StackPanel>
139142
<TextBlock
140143
Margin="0"
@@ -152,9 +155,9 @@
152155
Grid.Row="0"
153156
Grid.Column="3"
154157
Margin="4,0,0,0"
155-
Click="ButtonAction_OnClick"
156-
Icon="Gift24"
157-
Tag="icons">
158+
Command="{Binding ViewModel.ViewCommand}"
159+
CommandParameter="navigate_to_icons"
160+
Icon="Gift24">
158161
<StackPanel>
159162
<TextBlock
160163
Margin="0"
@@ -172,9 +175,9 @@
172175
Grid.Row="1"
173176
Grid.Column="0"
174177
Margin="0,8,4,0"
175-
Click="ButtonAction_OnClick"
176-
Icon="StoreMicrosoft24"
177-
Tag="window_store">
178+
Command="{Binding ViewModel.ViewCommand}"
179+
CommandParameter="open_window_store"
180+
Icon="StoreMicrosoft24">
178181
<StackPanel>
179182
<TextBlock
180183
Margin="0"
@@ -192,9 +195,9 @@
192195
Grid.Row="1"
193196
Grid.Column="1"
194197
Margin="4,8,4,0"
195-
Click="ButtonAction_OnClick"
196-
Icon="DataArea24"
197-
Tag="window_manager">
198+
Command="{Binding ViewModel.ViewCommand}"
199+
CommandParameter="open_window_manager"
200+
Icon="DataArea24">
198201
<StackPanel>
199202
<TextBlock
200203
Margin="0"
@@ -212,9 +215,9 @@
212215
Grid.Row="1"
213216
Grid.Column="2"
214217
Margin="4,8,4,0"
215-
Click="ButtonAction_OnClick"
216-
Icon="TextHeader124"
217-
Tag="window_editor">
218+
Command="{Binding ViewModel.ViewCommand}"
219+
CommandParameter="open_window_editor"
220+
Icon="TextHeader124">
218221
<StackPanel>
219222
<TextBlock
220223
Margin="0"
@@ -232,9 +235,9 @@
232235
Grid.Row="1"
233236
Grid.Column="3"
234237
Margin="4,8,0,0"
235-
Click="ButtonAction_OnClick"
236-
Icon="Settings24"
237-
Tag="window_settings">
238+
Command="{Binding ViewModel.ViewCommand}"
239+
CommandParameter="open_window_settings"
240+
Icon="Settings24">
238241
<StackPanel>
239242
<TextBlock
240243
Margin="0"
@@ -269,7 +272,8 @@
269272
NavigateUri="https://www.nuget.org/packages/WPF-UI/" />
270273
<ui:Hyperlink
271274
Grid.Row="2"
272-
Click="ButtonExperimental_OnClick"
275+
Command="{Binding ViewModel.ViewCommand}"
276+
CommandParameter="open_window_experimental"
273277
Content="Launch experimental window"
274278
Icon="Link48" />
275279
</Grid>

0 commit comments

Comments
 (0)