Skip to content

Commit 522a533

Browse files
committed
Added base sample application and sample for FilePicker
1 parent fc900a2 commit 522a533

24 files changed

Lines changed: 515 additions & 1878 deletions

File tree

samples/MADE.NET.Samples.sln

Lines changed: 0 additions & 1660 deletions
This file was deleted.

samples/MADE.Samples.Windows/MADE.Samples.Windows.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
</Page>
151151
</ItemGroup>
152152
<ItemGroup>
153+
<PackageReference Include="CommunityToolkit.Mvvm">
154+
<Version>7.0.3</Version>
155+
</PackageReference>
156+
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
157+
<Version>5.0.2</Version>
158+
</PackageReference>
153159
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
154160
<Version>6.2.11</Version>
155161
</PackageReference>

samples/MADE.Samples/MADE.Samples.Droid/MADE.Samples.Droid.csproj

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@
6060
<Reference Include="System.Xml" />
6161
</ItemGroup>
6262
<ItemGroup>
63+
<PackageReference Include="CommunityToolkit.Mvvm">
64+
<Version>7.0.3</Version>
65+
</PackageReference>
66+
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
67+
<Version>5.0.2</Version>
68+
</PackageReference>
6369
<PackageReference Include="Uno.UI" Version="3.9.7" />
6470
<PackageReference Include="Uno.UI.RemoteControl" Version="3.9.7" Condition="'$(Configuration)'=='Debug'" />
6571
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.35" />
66-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
67-
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
6872
</ItemGroup>
6973
<ItemGroup>
7074
<Compile Include="MainActivity.cs" />
@@ -125,10 +129,26 @@
125129
<Project>{e2b20928-dae2-4a9c-bdaf-d787b4f48391}</Project>
126130
<Name>MADE.UI.Controls.Validator</Name>
127131
</ProjectReference>
132+
<ProjectReference Include="..\..\..\src\MADE.UI.Styling\MADE.UI.Styling.csproj">
133+
<Project>{f8d00106-0598-45e7-b92e-ef408249c02e}</Project>
134+
<Name>MADE.UI.Styling</Name>
135+
</ProjectReference>
136+
<ProjectReference Include="..\..\..\src\MADE.UI.ViewManagement\MADE.UI.ViewManagement.csproj">
137+
<Project>{442d1e25-ffd1-405d-a1fc-40cafcad190c}</Project>
138+
<Name>MADE.UI.ViewManagement</Name>
139+
</ProjectReference>
128140
<ProjectReference Include="..\..\..\src\MADE.UI.Views.Dialogs\MADE.UI.Views.Dialogs.csproj">
129141
<Project>{2b5c0bea-18d8-4b82-af64-ede15505e793}</Project>
130142
<Name>MADE.UI.Views.Dialogs</Name>
131143
</ProjectReference>
144+
<ProjectReference Include="..\..\..\src\MADE.UI.Views.Navigation.Mvvm\MADE.UI.Views.Navigation.Mvvm.csproj">
145+
<Project>{0ca60466-059c-42d3-9b68-6bbb75a75090}</Project>
146+
<Name>MADE.UI.Views.Navigation.Mvvm</Name>
147+
</ProjectReference>
148+
<ProjectReference Include="..\..\..\src\MADE.UI.Views.Navigation\MADE.UI.Views.Navigation.csproj">
149+
<Project>{99e31579-1168-4983-bced-e7853e33ef5b}</Project>
150+
<Name>MADE.UI.Views.Navigation</Name>
151+
</ProjectReference>
132152
<ProjectReference Include="..\..\..\src\MADE.UI\MADE.UI.csproj">
133153
<Project>{79afd8fc-7789-47b7-b808-26e03d0f1e05}</Project>
134154
<Name>MADE.UI</Name>
Lines changed: 73 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,111 @@
1-
using Microsoft.Extensions.Logging;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.IO;
5-
using System.Linq;
6-
using System.Runtime.InteropServices.WindowsRuntime;
7-
using Windows.ApplicationModel;
8-
using Windows.ApplicationModel.Activation;
9-
using Windows.Foundation;
10-
using Windows.Foundation.Collections;
11-
using Windows.UI.Xaml;
12-
using Windows.UI.Xaml.Controls;
13-
using Windows.UI.Xaml.Controls.Primitives;
14-
using Windows.UI.Xaml.Data;
15-
using Windows.UI.Xaml.Input;
16-
using Windows.UI.Xaml.Media;
17-
using Windows.UI.Xaml.Navigation;
18-
191
namespace MADE.Samples
202
{
21-
using MADE.UI.Views.Dialogs;
3+
using System;
4+
using System.Threading.Tasks;
5+
using CommunityToolkit.Mvvm.DependencyInjection;
6+
using CommunityToolkit.Mvvm.Messaging;
7+
using MADE.Diagnostics;
8+
using MADE.Diagnostics.Logging;
9+
using MADE.Samples.Features.Home.Pages;
10+
using MADE.Samples.Infrastructure.ViewModels;
11+
using MADE.UI.Views.Navigation;
12+
using Microsoft.Extensions.DependencyInjection;
13+
using Windows.ApplicationModel.Activation;
14+
using Windows.UI.Xaml;
15+
using Windows.UI.Xaml.Controls;
16+
using Windows.UI.Xaml.Navigation;
2217

2318
/// <summary>
24-
/// Provides application-specific behavior to supplement the default Application class.
19+
/// Defines application-specific behavior to supplement the default Application class.
2520
/// </summary>
2621
public sealed partial class App : Application
2722
{
28-
/// <summary>
29-
/// Initializes the singleton application object. This is the first line of authored code
30-
/// executed, and as such is the logical equivalent of main() or WinMain().
31-
/// </summary>
23+
private IServiceProvider serviceProvider;
24+
3225
public App()
3326
{
3427
this.InitializeComponent();
35-
this.Suspending += OnSuspending;
3628
}
3729

38-
public static AppDialog Dialog { get; private set; }
39-
40-
/// <summary>
41-
/// Invoked when the application is launched normally by the end user. Other entry points
42-
/// will be used such as when the application is launched to open a specific file.
43-
/// </summary>
44-
/// <param name="e">Details about the launch request and process.</param>
45-
protected override void OnLaunched(LaunchActivatedEventArgs e)
30+
public static IServiceProvider Services
4631
{
47-
#if DEBUG
48-
if (System.Diagnostics.Debugger.IsAttached)
32+
get
4933
{
50-
// this.DebugSettings.EnableFrameRateCounter = true;
34+
IServiceProvider serviceProvider = ((App)Current).serviceProvider;
35+
36+
if (serviceProvider is null)
37+
{
38+
throw new InvalidOperationException("Service provider is not initialized.");
39+
}
40+
41+
return serviceProvider;
5142
}
52-
#endif
43+
}
44+
45+
46+
protected override async void OnLaunched(LaunchActivatedEventArgs e)
47+
{
48+
await this.ActivateAsync(e.PrelaunchActivated);
49+
}
50+
51+
protected override async void OnActivated(IActivatedEventArgs args)
52+
{
53+
await this.ActivateAsync(false);
54+
}
55+
56+
private static IServiceProvider ConfigureServices(Frame rootFrame)
57+
{
58+
Ioc.Default.ConfigureServices(
59+
new ServiceCollection()
60+
.AddSingleton<IMessenger>(provider => WeakReferenceMessenger.Default)
61+
.AddSingleton<IEventLogger, FileEventLogger>()
62+
.AddSingleton<IAppDiagnostics, AppDiagnostics>()
63+
.AddSingleton<INavigationService>(provider => new NavigationService(rootFrame))
64+
.AddViewModels()
65+
.BuildServiceProvider());
66+
67+
return Ioc.Default;
68+
}
5369

70+
private static void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
71+
{
72+
throw new InvalidOperationException($"Failed to load page {e.SourcePageType.FullName}.");
73+
}
74+
75+
private async Task ActivateAsync(bool isPrelaunch)
76+
{
5477
#if NET5_0 && WINDOWS
5578
var window = new Window();
5679
window.Activate();
5780
#else
58-
var window = Windows.UI.Xaml.Window.Current;
81+
Window window = Windows.UI.Xaml.Window.Current;
5982
#endif
6083

61-
Frame rootFrame = window.Content as Frame;
62-
63-
// Do not repeat app initialization when the Window already has content,
64-
// just ensure that the window is active
65-
if (rootFrame == null)
84+
if (!(window.Content is Frame rootFrame))
6685
{
67-
// Create a Frame to act as the navigation context and navigate to the first page
6886
rootFrame = new Frame();
69-
7087
rootFrame.NavigationFailed += OnNavigationFailed;
7188

72-
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
89+
window.Content = rootFrame;
90+
91+
this.serviceProvider = ConfigureServices(rootFrame);
92+
93+
IAppDiagnostics diagnostics = this.serviceProvider.GetService<IAppDiagnostics>();
94+
if (diagnostics != null)
7395
{
74-
//TODO: Load state from previously suspended application
96+
await diagnostics.StartRecordingDiagnosticsAsync();
7597
}
76-
77-
// Place the frame in the current Window
78-
window.Content = rootFrame;
7998
}
8099

81-
Dialog = new AppDialog(rootFrame.Dispatcher);
82-
83-
#if !(NET5_0 && WINDOWS)
84-
if (e.PrelaunchActivated == false)
85-
#endif
100+
if (!isPrelaunch)
86101
{
87-
if (rootFrame.Content == null)
102+
if (rootFrame.Content is null)
88103
{
89-
// When the navigation stack isn't restored navigate to the first page,
90-
// configuring the new page by passing required information as a navigation
91-
// parameter
92-
rootFrame.Navigate(typeof(MainPage), e.Arguments);
104+
rootFrame.Navigate(typeof(MainPage));
93105
}
94-
// Ensure the current window is active
106+
95107
window.Activate();
96108
}
97109
}
98-
99-
/// <summary>
100-
/// Invoked when Navigation to a certain page fails
101-
/// </summary>
102-
/// <param name="sender">The Frame which failed navigation</param>
103-
/// <param name="e">Details about the navigation failure</param>
104-
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
105-
{
106-
throw new Exception($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
107-
}
108-
109-
/// <summary>
110-
/// Invoked when application execution is being suspended. Application state is saved
111-
/// without knowing whether the application will be terminated or resumed with the contents
112-
/// of memory still intact.
113-
/// </summary>
114-
/// <param name="sender">The source of the suspend request.</param>
115-
/// <param name="e">Details about the suspend request.</param>
116-
private void OnSuspending(object sender, SuspendingEventArgs e)
117-
{
118-
var deferral = e.SuspendingOperation.GetDeferral();
119-
//TODO: Save application state and stop any background activity
120-
deferral.Complete();
121-
}
122110
}
123111
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<pages:MvvmPage
2+
x:Class="MADE.Samples.Features.Home.Pages.MainPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:extensions="using:MADE.UI.Extensions"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:pages="using:MADE.UI.Views.Navigation.Pages"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
10+
mc:Ignorable="d">
11+
12+
<Grid Padding="12">
13+
<GridView
14+
extensions:ListViewBaseExtensions.ItemClickCommand="{x:Bind ViewModel.NavigateToSampleCommand}"
15+
IsItemClickEnabled="true"
16+
ItemsSource="{x:Bind ViewModel.Samples}" />
17+
</Grid>
18+
</pages:MvvmPage>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MADE.Samples.Features.Home.Pages
2+
{
3+
using MADE.Samples.Features.Home.ViewModels;
4+
using MADE.UI.Views.Navigation.Pages;
5+
using Microsoft.Extensions.DependencyInjection;
6+
7+
public sealed partial class MainPage : MvvmPage
8+
{
9+
public MainPage()
10+
{
11+
this.InitializeComponent();
12+
this.DataContext = App.Services.GetService<MainPageViewModel>();
13+
}
14+
15+
public MainPageViewModel ViewModel => this.DataContext as MainPageViewModel;
16+
}
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace MADE.Samples.Features.Home.ViewModels
2+
{
3+
using System.Collections.Generic;
4+
using System.Windows.Input;
5+
using CommunityToolkit.Mvvm.Input;
6+
using CommunityToolkit.Mvvm.Messaging;
7+
using MADE.Samples.Features.Samples.Data;
8+
using MADE.UI.Views.Navigation;
9+
using MADE.UI.Views.Navigation.ViewModels;
10+
using MADE.Samples.Features.Samples.Pages;
11+
12+
public class MainPageViewModel : PageViewModel
13+
{
14+
public MainPageViewModel(INavigationService navigationService, IMessenger messenger)
15+
: base(navigationService, messenger)
16+
{
17+
}
18+
19+
public ICommand NavigateToSampleCommand => new RelayCommand<Sample>(this.NavigateToSample);
20+
21+
public ICollection<Sample> Samples { get; } = new List<Sample>
22+
{
23+
new Sample
24+
{
25+
Name = "FileInput",
26+
Category = "Controls",
27+
Page = typeof(FilePickerPage)
28+
}
29+
};
30+
31+
private void NavigateToSample(Sample sample)
32+
{
33+
this.NavigationService.NavigateTo(sample.Page);
34+
}
35+
}
36+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MADE.Samples.Features.Samples.Data
2+
{
3+
using System;
4+
5+
public class Sample
6+
{
7+
public string Name { get; set; }
8+
9+
public string Description { get; set; }
10+
11+
public string Category { get; set; }
12+
13+
public string IconPath { get; set; }
14+
15+
public Type Page { get; set; }
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace MADE.Samples.Features.Samples.Pages
2+
{
3+
using CommunityToolkit.Mvvm.Messaging;
4+
using MADE.Samples.Features.Samples.ViewModels;
5+
using MADE.UI.Views.Navigation;
6+
using MADE.UI.Views.Navigation.Pages;
7+
using Microsoft.Extensions.DependencyInjection;
8+
9+
public sealed partial class FilePickerPage : MvvmPage
10+
{
11+
public FilePickerPage()
12+
{
13+
this.InitializeComponent();
14+
this.DataContext = new FileInputSamplePageViewModel(
15+
App.Services.GetService<INavigationService>(),
16+
App.Services.GetService<IMessenger>());
17+
}
18+
19+
public FileInputSamplePageViewModel ViewModel => this.DataContext as FileInputSamplePageViewModel;
20+
}
21+
}

0 commit comments

Comments
 (0)