Skip to content

Commit

Permalink
Extend navigation aware pages with INavigableView<T> interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed Jul 5, 2022
1 parent a792c0c commit 838cd35
Show file tree
Hide file tree
Showing 21 changed files with 245 additions and 170 deletions.
1 change: 1 addition & 0 deletions src/Wpf.Ui.Demo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public partial class App

// Views and ViewModels
services.AddScoped<Views.Pages.Dashboard>();
services.AddScoped<DashboardViewModel>();

services.AddScoped<Views.Pages.ExperimentalDashboard>();
services.AddScoped<ExperimentalViewModel>();
Expand Down
3 changes: 3 additions & 0 deletions src/Wpf.Ui.Demo/ViewModels/ButtonsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class ButtonsViewModel : Wpf.Ui.Mvvm.ViewModelBase
public ButtonsViewModel(INavigationService navigationService)
{
_navigationService = navigationService;

var testGetThemeService = App.GetService<IThemeService>();
var currentTheme = testGetThemeService.GetSystemTheme();
}

protected override void OnViewCommand(object parameter = null)
Expand Down
94 changes: 94 additions & 0 deletions src/Wpf.Ui.Demo/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 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.

using Wpf.Ui.Common.Interfaces;
using Wpf.Ui.Demo.Services.Contracts;
using Wpf.Ui.Mvvm.Contracts;

namespace Wpf.Ui.Demo.ViewModels;

public class DashboardViewModel : Wpf.Ui.Mvvm.ViewModelBase, INavigationAware
{
private readonly INavigationService _navigationService;

private readonly ITestWindowService _testWindowService;

public DashboardViewModel(INavigationService navigationService, ITestWindowService testWindowService)
{
_navigationService = navigationService;
_testWindowService = testWindowService;
}

protected override void OnViewCommand(object parameter = null)
{
if (parameter is not string parameterString)
return;

if (parameterString.StartsWith("navigate_to"))
OnNavigateCommand(parameterString);

if (parameterString.StartsWith("open_window"))
OnOpenWindowCommand(parameterString);
}

public void OnNavigatedTo()
{
System.Diagnostics.Debug.WriteLine($"INFO | {typeof(DashboardViewModel)} navigated", "Wpf.Ui.Demo");
}

public void OnNavigatedFrom()
{
System.Diagnostics.Debug.WriteLine($"INFO | {typeof(DashboardViewModel)} navigated", "Wpf.Ui.Demo");
}

private void OnNavigateCommand(string parameter)
{
switch (parameter)
{
case "navigate_to_input":
_navigationService.Navigate(typeof(Views.Pages.Input));
return;

case "navigate_to_controls":
_navigationService.Navigate(typeof(Views.Pages.Controls));
return;

case "navigate_to_colors":
_navigationService.Navigate(typeof(Views.Pages.Colors));
return;

case "navigate_to_icons":
_navigationService.Navigate(typeof(Views.Pages.Icons));
return;
}
}

private void OnOpenWindowCommand(string parameter)
{
switch (parameter)
{
case "open_window_store":
_testWindowService.Show<Views.Windows.StoreWindow>();
return;

case "open_window_manager":
_testWindowService.Show<Views.Windows.TaskManagerWindow>();
return;

case "open_window_editor":
_testWindowService.Show<Views.Windows.EditorWindow>();
return;

case "open_window_settings":
_testWindowService.Show<Views.Windows.SettingsWindow>();
return;

case "open_window_experimental":
_testWindowService.Show<Views.Windows.ExperimentalWindow>();
return;
}
}
}

9 changes: 2 additions & 7 deletions src/Wpf.Ui.Demo/Views/Pages/Buttons.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using Wpf.Ui.Common.Interfaces;
using Wpf.Ui.Demo.ViewModels;
using Wpf.Ui.Mvvm.Contracts;

namespace Wpf.Ui.Demo.Views.Pages;

/// <summary>
/// Interaction logic for Buttons.xaml
/// </summary>
public partial class Buttons
public partial class Buttons : INavigableView<ButtonsViewModel>
{
public ButtonsViewModel ViewModel
{
Expand All @@ -20,12 +20,7 @@ public ButtonsViewModel ViewModel

public Buttons(ButtonsViewModel viewModel)
{
//ViewModel = App.GetService<ButtonsViewModel>();
ViewModel = viewModel;
DataContext = this;

var testGetThemeService = App.GetService<IThemeService>();
var currentTheme = testGetThemeService.GetSystemTheme();

InitializeComponent();
}
Expand Down
12 changes: 5 additions & 7 deletions src/Wpf.Ui.Demo/Views/Pages/Colors.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.Ui.Demo.Views.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:Wpf.Ui.Demo.Views.Pages"
xmlns:viewModels="clr-namespace:Wpf.Ui.Demo.ViewModels"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="Colors"
d:DataContext="{d:DesignInstance viewModels:ColorsViewModel,
d:DataContext="{d:DesignInstance local:Colors,
IsDesignTimeCreatable=False}"
d:DesignHeight="450"
d:DesignWidth="800"
Expand All @@ -37,10 +35,10 @@
<ItemsControl
Grid.Row="0"
Margin="-4,0,-4,0"
ItemsSource="{Binding PaletteBrushes, Mode=OneWay}">
ItemsSource="{Binding ViewModel.PaletteBrushes, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding Columns, Mode=OneWay}" />
<UniformGrid Columns="{Binding ViewModel.Columns, Mode=OneWay}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
Expand All @@ -66,10 +64,10 @@
<ItemsControl
Grid.Row="2"
Margin="-4,0,-4,0"
ItemsSource="{Binding ThemeBrushes, Mode=OneWay}">
ItemsSource="{Binding ViewModel.ThemeBrushes, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding Columns, Mode=OneWay}" />
<UniformGrid Columns="{Binding ViewModel.Columns, Mode=OneWay}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
Expand Down
11 changes: 9 additions & 2 deletions src/Wpf.Ui.Demo/Views/Pages/Colors.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using Wpf.Ui.Common.Interfaces;
using Wpf.Ui.Demo.ViewModels;

namespace Wpf.Ui.Demo.Views.Pages;

/// <summary>
/// Interaction logic for Colors.xaml
/// </summary>
public partial class Colors
public partial class Colors : INavigableView<ColorsViewModel>
{
public ColorsViewModel ViewModel
{
get;
}

public Colors(ColorsViewModel viewModel)
{
DataContext = viewModel;
ViewModel = viewModel;

InitializeComponent();
}
}
4 changes: 2 additions & 2 deletions src/Wpf.Ui.Demo/Views/Pages/Controls.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
Title="Controls"
d:DesignHeight="1750"
d:DesignWidth="800"
Loaded="Controls_OnLoaded"
Loaded="OnLoaded"
Scrollable="True"
Unloaded="Controls_OnUnloaded"
Unloaded="OnUnloaded"
mc:Ignorable="d">

<VirtualizingStackPanel
Expand Down
4 changes: 2 additions & 2 deletions src/Wpf.Ui.Demo/Views/Pages/Controls.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public Controls(ISnackbarService snackbarService, IDialogService dialogService)
_dialogControl = dialogService.GetDialogControl();
}

private void Controls_OnLoaded(object sender, RoutedEventArgs e)
private void OnLoaded(object sender, RoutedEventArgs e)
{
RootPanel.ScrollOwner = ScrollHost;

_dialogControl.ButtonRightClick += DialogControlOnButtonRightClick;
}

private void Controls_OnUnloaded(object sender, RoutedEventArgs e)
private void OnUnloaded(object sender, RoutedEventArgs e)
{
_dialogControl.ButtonRightClick -= DialogControlOnButtonRightClick;
}
Expand Down
56 changes: 30 additions & 26 deletions src/Wpf.Ui.Demo/Views/Pages/Dashboard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="Dashboard"
d:DataContext="{d:DesignInstance local:Dashboard,
IsDesignTimeCreatable=False}"
d:DesignHeight="750"
d:DesignWidth="800"
Scrollable="True"
Expand Down Expand Up @@ -61,7 +63,8 @@
Padding="30,6"
HorizontalAlignment="Left"
Appearance="Transparent"
Click="ButtonControls_OnClick"
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="navigate_to_controls"
Content="Check out the controls"
Foreground="{DynamicResource TextFillColorLightPrimaryBrush}" />
</StackPanel>
Expand Down Expand Up @@ -92,9 +95,9 @@
Grid.Row="0"
Grid.Column="0"
Margin="0,0,4,0"
Click="ButtonAction_OnClick"
Icon="TextParagraph24"
Tag="input">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="navigate_to_input"
Icon="TextParagraph24">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -112,9 +115,9 @@
Grid.Row="0"
Grid.Column="1"
Margin="4,0,4,0"
Click="ButtonAction_OnClick"
Icon="Fluent24"
Tag="controls">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="navigate_to_controls"
Icon="Fluent24">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -132,9 +135,9 @@
Grid.Row="0"
Grid.Column="2"
Margin="4,0,4,0"
Click="ButtonAction_OnClick"
Icon="Color16"
Tag="colors">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="navigate_to_colors"
Icon="Color16">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -152,9 +155,9 @@
Grid.Row="0"
Grid.Column="3"
Margin="4,0,0,0"
Click="ButtonAction_OnClick"
Icon="Gift24"
Tag="icons">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="navigate_to_icons"
Icon="Gift24">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -172,9 +175,9 @@
Grid.Row="1"
Grid.Column="0"
Margin="0,8,4,0"
Click="ButtonAction_OnClick"
Icon="StoreMicrosoft24"
Tag="window_store">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="open_window_store"
Icon="StoreMicrosoft24">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -192,9 +195,9 @@
Grid.Row="1"
Grid.Column="1"
Margin="4,8,4,0"
Click="ButtonAction_OnClick"
Icon="DataArea24"
Tag="window_manager">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="open_window_manager"
Icon="DataArea24">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -212,9 +215,9 @@
Grid.Row="1"
Grid.Column="2"
Margin="4,8,4,0"
Click="ButtonAction_OnClick"
Icon="TextHeader124"
Tag="window_editor">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="open_window_editor"
Icon="TextHeader124">
<StackPanel>
<TextBlock
Margin="0"
Expand All @@ -232,9 +235,9 @@
Grid.Row="1"
Grid.Column="3"
Margin="4,8,0,0"
Click="ButtonAction_OnClick"
Icon="Settings24"
Tag="window_settings">
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="open_window_settings"
Icon="Settings24">
<StackPanel>
<TextBlock
Margin="0"
Expand Down Expand Up @@ -269,7 +272,8 @@
NavigateUri="https://www.nuget.org/packages/WPF-UI/" />
<ui:Hyperlink
Grid.Row="2"
Click="ButtonExperimental_OnClick"
Command="{Binding ViewModel.ViewCommand}"
CommandParameter="open_window_experimental"
Content="Launch experimental window"
Icon="Link48" />
</Grid>
Expand Down
Loading

0 comments on commit 838cd35

Please sign in to comment.