Add Xamarin Forms Sample
|
@ -7,9 +7,9 @@ dev_langs:
|
|||
- csharp
|
||||
---
|
||||
|
||||
# Ioc ([Inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control))
|
||||
# Ioc (Inversion of control)
|
||||
|
||||
Inversion of Control is a common pattern that can be used to increase modularity in the codebase of an application when using the MVVM pattern. A frequently used way to enable this is to use _dependency injection_ (DI), which consists of creating a number of services that are injected into backend classes (i.e. passed as parameters to the viewmodel constructors). Doing this allows code using these services not to rely on the implementation details of these services, and it also makes it easy to swap the concrete implementations of these services. This pattern also makes it easy to make platform-specific features available to backend code, by abstracting them through a service which is then injected where needed. Since services are then isolated from where they are used, they become more testable as well.
|
||||
[Inversion of Control](https://en.wikipedia.org/wiki/Inversion_of_control) is a common pattern that can be used to increase modularity in the codebase of an application when using the MVVM pattern. A frequently used way to enable this is to use _dependency injection_ (DI), which consists of creating a number of services that are injected into backend classes (i.e. passed as parameters to the viewmodel constructors). Doing this allows code using these services not to rely on the implementation details of these services, and it also makes it easy to swap the concrete implementations of these services. This pattern also makes it easy to make platform-specific features available to backend code, by abstracting them through a service which is then injected where needed. Since services are then isolated from where they are used, they become more testable as well.
|
||||
|
||||
The MVVM Toolkit doesn't provide built-in APIs to facilitate the usage of this pattern, as dedicated libraries specifically exist for this, such as the `Microsoft.Extensions.DependencyInjection` package. It provides a fully featured and powerful set of dependency injection APIs already and can be easily setup to use the [`IServiceProvider`](https://docs.microsoft.com/dotnet/api/system.iserviceprovider) interface. The following guide will refer to this library and provide a series of examples of how to integrate it into applications using the MVVM pattern with the MVVM Toolkit.
|
||||
|
|
@ -7,7 +7,7 @@ dev_langs:
|
|||
- csharp
|
||||
---
|
||||
|
||||
# RelayCommand and RelayCommand<T>
|
||||
# RelayCommand
|
||||
|
||||
The [`RelayCommand`](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.mvvm.input.RelayCommand) and [`RelayCommand<T>`](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.mvvm.input.RelayCommand-1) are `ICommand` implementations that can expose a method or delegate to the view. These types act as a way to bind commands between the viewmodel and UI elements.
|
||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MvvmSampleUwp.Helpers
|
||||
namespace MvvmSample.Core.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple class to help with basic operations on markdown documents.
|
||||
|
@ -21,7 +21,8 @@ namespace MvvmSampleUwp.Helpers
|
|||
public static IReadOnlyDictionary<string, string> GetParagraphs(string text)
|
||||
{
|
||||
return
|
||||
Regex.Matches(text, @"(?<=\W)#+ ([^\n]+).+?(?=\W#|$)", RegexOptions.Singleline)
|
||||
Regex.Matches(text, @"(?<=\W)#+ ([^\n]+).+?(?=\W#|$)", RegexOptions.Singleline)
|
||||
.OfType<Match>()
|
||||
.ToDictionary(
|
||||
m => m.Groups[1].Value.Trim().Replace("<", "<"),
|
||||
m => m.Groups[0].Value.Trim().Replace("<", "<").Replace("[!WARNING]", "**WARNING:**").Replace("[!NOTE]", "**NOTE:**"));
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MvvmSampleUwp.Models
|
||||
namespace MvvmSample.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A class for a query for posts in a given subreddit.
|
||||
|
@ -69,7 +69,7 @@ namespace MvvmSampleUwp.Models
|
|||
/// Normally, not all posts have a self text post available.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public string SelfText { get; } = string.Join(' ', Enumerable.Repeat(
|
||||
public string SelfText { get; } = string.Join(" ", Enumerable.Repeat(
|
||||
@"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
|
@ -0,0 +1,51 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<UserSecretsId>4e66f7b4-01a8-4f00-8733-4ae6a08c741f</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Docs\AsyncRelayCommand.md" />
|
||||
<None Remove="Docs\Introduction.md" />
|
||||
<None Remove="Docs\Ioc.md" />
|
||||
<None Remove="Docs\Messenger.md" />
|
||||
<None Remove="Docs\ObservableObject.md" />
|
||||
<None Remove="Docs\ObservableRecipient.md" />
|
||||
<None Remove="Docs\PuttingThingsTogether.md" />
|
||||
<None Remove="Docs\RelayCommand.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Docs\AsyncRelayCommand.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\Introduction.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\Ioc.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\Messenger.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\ObservableObject.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\ObservableRecipient.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\PuttingThingsTogether.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Docs\RelayCommand.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.0.0-preview5" />
|
||||
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.0" />
|
||||
<PackageReference Include="Refit" Version="5.2.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -5,7 +5,7 @@
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MvvmSampleUwp.Services
|
||||
namespace MvvmSample.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// The default <see langword="interface"/> for a service that handles files.
|
|
@ -3,10 +3,10 @@
|
|||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using MvvmSampleUwp.Models;
|
||||
using MvvmSample.Core.Models;
|
||||
using Refit;
|
||||
|
||||
namespace MvvmSampleUwp.Services
|
||||
namespace MvvmSample.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface for a simple Reddit service.
|
|
@ -5,7 +5,7 @@
|
|||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace MvvmSampleUwp.Services
|
||||
namespace MvvmSample.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// The default <see langword="interface"/> for the settings manager used in the app.
|
|
@ -5,7 +5,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels
|
||||
namespace MvvmSample.Core.ViewModels
|
||||
{
|
||||
public class AsyncRelayCommandPageViewModel : SamplePageViewModel
|
||||
{
|
|
@ -2,7 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels
|
||||
namespace MvvmSample.Core.ViewModels
|
||||
{
|
||||
public class IocPageViewModel : SamplePageViewModel
|
||||
{
|
|
@ -3,13 +3,24 @@
|
|||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Toolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using Microsoft.Toolkit.Mvvm.Messaging;
|
||||
using Microsoft.Toolkit.Mvvm.Messaging.Messages;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels
|
||||
namespace MvvmSample.Core.ViewModels
|
||||
{
|
||||
public class MessengerPageViewModel : SamplePageViewModel
|
||||
{
|
||||
public MessengerPageViewModel()
|
||||
{
|
||||
RequestCurrentUsernameCommand = new RelayCommand(RequestCurrentUsername);
|
||||
ResetCurrentUsernameCommand = new RelayCommand(ResetCurrentUsername);
|
||||
}
|
||||
|
||||
public ICommand RequestCurrentUsernameCommand { get; }
|
||||
public ICommand ResetCurrentUsernameCommand { get; }
|
||||
|
||||
public UserSenderViewModel SenderViewModel { get; } = new UserSenderViewModel();
|
||||
|
||||
public UserReceiverViewModel ReceiverViewModel { get; } = new UserReceiverViewModel();
|
||||
|
@ -17,6 +28,13 @@ namespace MvvmSampleUwp.ViewModels
|
|||
// Simple viewmodel for a module sending a username message
|
||||
public class UserSenderViewModel : ObservableRecipient
|
||||
{
|
||||
public UserSenderViewModel()
|
||||
{
|
||||
SendUserMessageCommand = new RelayCommand(SendUserMessage);
|
||||
}
|
||||
|
||||
public ICommand SendUserMessageCommand { get; }
|
||||
|
||||
private string username = "Bob";
|
||||
|
||||
public string Username
|
|
@ -2,12 +2,24 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels
|
||||
namespace MvvmSample.Core.ViewModels
|
||||
{
|
||||
public class ObservableObjectPageViewModel : SamplePageViewModel
|
||||
{
|
||||
public ObservableObjectPageViewModel()
|
||||
{
|
||||
ReloadTaskCommand = new RelayCommand(ReloadTask);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ICommand"/> responsible for setting <see cref="MyTask"/>.
|
||||
/// </summary>
|
||||
public ICommand ReloadTaskCommand { get; }
|
||||
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
|
@ -5,7 +5,7 @@
|
|||
using System.Windows.Input;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels
|
||||
namespace MvvmSample.Core.ViewModels
|
||||
{
|
||||
public class RelayCommandPageViewModel : SamplePageViewModel
|
||||
{
|
|
@ -5,20 +5,20 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Toolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Toolkit.Mvvm.DependencyInjection;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using MvvmSampleUwp.Helpers;
|
||||
using MvvmSampleUwp.Services;
|
||||
using MvvmSample.Core.Helpers;
|
||||
using MvvmSample.Core.Services;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels
|
||||
namespace MvvmSample.Core.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// A base class for viewmodels for sample pages in the app.
|
||||
/// </summary>
|
||||
public class SamplePageViewModel : ObservableObject
|
||||
{
|
||||
private IReadOnlyDictionary<string, string> texts;
|
||||
/// <summary>
|
||||
/// The <see cref="IFilesService"/> instance currently in use.
|
||||
/// </summary>
|
||||
|
@ -34,7 +34,7 @@ namespace MvvmSampleUwp.ViewModels
|
|||
/// </summary>
|
||||
public IAsyncRelayCommand<string> LoadDocsCommand { get; }
|
||||
|
||||
private IReadOnlyDictionary<string, string> texts;
|
||||
public IReadOnlyDictionary<string, string> Texts { get => texts; set => SetProperty(ref texts, value); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the markdown for a specified paragraph from the docs page.
|
||||
|
@ -43,7 +43,7 @@ namespace MvvmSampleUwp.ViewModels
|
|||
/// <returns>The text of the specified paragraph, or <see langword="null"/>.</returns>
|
||||
public string GetParagraph(string key)
|
||||
{
|
||||
return texts != null && texts.TryGetValue(key, out var value) ? value : string.Empty;
|
||||
return Texts != null && Texts.TryGetValue(key, out var value) ? value : string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -55,14 +55,15 @@ namespace MvvmSampleUwp.ViewModels
|
|||
// Skip if the loading has already started
|
||||
if (!(LoadDocsCommand.ExecutionTask is null)) return;
|
||||
|
||||
var path = Path.Combine(FilesServices.InstallationPath, "Assets", "docs", $"{name}.md");
|
||||
var path = Path.Combine("Assets", "docs", $"{name}.md");
|
||||
using var stream = await FilesServices.OpenForReadAsync(path);
|
||||
using var reader = new StreamReader(stream);
|
||||
var text = await reader.ReadToEndAsync();
|
||||
|
||||
texts = MarkdownHelper.GetParagraphs(text);
|
||||
Texts = MarkdownHelper.GetParagraphs(text);
|
||||
|
||||
OnPropertyChanged(nameof(GetParagraph));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@
|
|||
using Microsoft.Toolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Toolkit.Mvvm.Messaging;
|
||||
using Microsoft.Toolkit.Mvvm.Messaging.Messages;
|
||||
using MvvmSampleUwp.Models;
|
||||
using MvvmSample.Core.Models;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels.Widgets
|
||||
namespace MvvmSample.Core.ViewModels.Widgets
|
||||
{
|
||||
/// <summary>
|
||||
/// A viewmodel for a post widget.
|
|
@ -5,15 +5,14 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Toolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Toolkit.Mvvm.DependencyInjection;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using MvvmSampleUwp.Models;
|
||||
using MvvmSampleUwp.Services;
|
||||
using MvvmSample.Core.Models;
|
||||
using MvvmSample.Core.Services;
|
||||
using Nito.AsyncEx;
|
||||
|
||||
namespace MvvmSampleUwp.ViewModels.Widgets
|
||||
namespace MvvmSample.Core.ViewModels.Widgets
|
||||
{
|
||||
/// <summary>
|
||||
/// A viewmodel for a subreddit widget.
|
|
@ -5,18 +5,23 @@ VisualStudioVersion = 16.0.30320.27
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmSampleUwp", "MvvmSampleUwp\MvvmSampleUwp.csproj", "{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmSample.Core", "MvvmSample.Core\MvvmSample.Core.csproj", "{28E524F7-61B3-455D-8CBD-615BC4FDE814}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|ARM = Debug|ARM
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|ARM = Release|ARM
|
||||
Release|ARM64 = Release|ARM64
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
|
@ -29,6 +34,7 @@ Global
|
|||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|x86.Build.0 = Debug|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|ARM.Build.0 = Release|ARM
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|ARM.Deploy.0 = Release|ARM
|
||||
|
@ -41,6 +47,26 @@ Global
|
|||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|x86.ActiveCfg = Release|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|x86.Build.0 = Release|x86
|
||||
{E667FBF4-30F2-49AC-8576-7A2B867F8F1A}.Release|x86.Deploy.0 = Release|x86
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|x64.Build.0 = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{28E524F7-61B3-455D-8CBD-615BC4FDE814}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
|
@ -7,9 +7,10 @@ using Windows.ApplicationModel.Core;
|
|||
using Windows.UI.Xaml;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Toolkit.Mvvm.DependencyInjection;
|
||||
using MvvmSampleUwp.Helpers;
|
||||
using MvvmSampleUwp.Services;
|
||||
using Refit;
|
||||
using MvvmSampleUwp.Helpers;
|
||||
using MvvmSample.Core.Services;
|
||||
|
||||
namespace MvvmSampleUwp
|
||||
{
|
До Ширина: | Высота: | Размер: 2.3 KiB После Ширина: | Высота: | Размер: 2.3 KiB |
До Ширина: | Высота: | Размер: 2.6 KiB После Ширина: | Высота: | Размер: 2.6 KiB |
До Ширина: | Высота: | Размер: 3.4 KiB После Ширина: | Высота: | Размер: 3.4 KiB |
До Ширина: | Высота: | Размер: 5.1 KiB После Ширина: | Высота: | Размер: 5.1 KiB |
До Ширина: | Высота: | Размер: 13 KiB После Ширина: | Высота: | Размер: 13 KiB |
До Ширина: | Высота: | Размер: 1.4 KiB После Ширина: | Высота: | Размер: 1.4 KiB |
До Ширина: | Высота: | Размер: 964 B После Ширина: | Высота: | Размер: 964 B |
До Ширина: | Высота: | Размер: 1.1 KiB После Ширина: | Высота: | Размер: 1.1 KiB |
До Ширина: | Высота: | Размер: 1.2 KiB После Ширина: | Высота: | Размер: 1.2 KiB |
До Ширина: | Высота: | Размер: 1.4 KiB После Ширина: | Высота: | Размер: 1.4 KiB |
До Ширина: | Высота: | Размер: 2.6 KiB После Ширина: | Высота: | Размер: 2.6 KiB |
До Ширина: | Высота: | Размер: 2.7 KiB После Ширина: | Высота: | Размер: 2.7 KiB |
До Ширина: | Высота: | Размер: 3.3 KiB После Ширина: | Высота: | Размер: 3.3 KiB |
До Ширина: | Высота: | Размер: 4.3 KiB После Ширина: | Высота: | Размер: 4.3 KiB |
До Ширина: | Высота: | Размер: 7.5 KiB После Ширина: | Высота: | Размер: 7.5 KiB |
До Ширина: | Высота: | Размер: 18 KiB После Ширина: | Высота: | Размер: 18 KiB |
До Ширина: | Высота: | Размер: 1.3 KiB После Ширина: | Высота: | Размер: 1.3 KiB |
До Ширина: | Высота: | Размер: 1.5 KiB После Ширина: | Высота: | Размер: 1.5 KiB |
До Ширина: | Высота: | Размер: 1.8 KiB После Ширина: | Высота: | Размер: 1.8 KiB |
До Ширина: | Высота: | Размер: 2.9 KiB После Ширина: | Высота: | Размер: 2.9 KiB |
До Ширина: | Высота: | Размер: 4.8 KiB После Ширина: | Высота: | Размер: 4.8 KiB |
До Ширина: | Высота: | Размер: 395 B После Ширина: | Высота: | Размер: 395 B |
До Ширина: | Высота: | Размер: 583 B После Ширина: | Высота: | Размер: 583 B |
До Ширина: | Высота: | Размер: 2.8 KiB После Ширина: | Высота: | Размер: 2.8 KiB |
До Ширина: | Высота: | Размер: 593 B После Ширина: | Высота: | Размер: 593 B |
До Ширина: | Высота: | Размер: 747 B После Ширина: | Высота: | Размер: 747 B |
До Ширина: | Высота: | Размер: 395 B После Ширина: | Высота: | Размер: 395 B |
До Ширина: | Высота: | Размер: 2.8 KiB После Ширина: | Высота: | Размер: 2.8 KiB |
До Ширина: | Высота: | Размер: 593 B После Ширина: | Высота: | Размер: 593 B |
До Ширина: | Высота: | Размер: 747 B После Ширина: | Высота: | Размер: 747 B |
До Ширина: | Высота: | Размер: 652 B После Ширина: | Высота: | Размер: 652 B |
До Ширина: | Высота: | Размер: 850 B После Ширина: | Высота: | Размер: 850 B |
До Ширина: | Высота: | Размер: 999 B После Ширина: | Высота: | Размер: 999 B |
До Ширина: | Высота: | Размер: 1.6 KiB После Ширина: | Высота: | Размер: 1.6 KiB |
До Ширина: | Высота: | Размер: 2.0 KiB После Ширина: | Высота: | Размер: 2.0 KiB |
До Ширина: | Высота: | Размер: 358 B После Ширина: | Высота: | Размер: 358 B |
До Ширина: | Высота: | Размер: 469 B После Ширина: | Высота: | Размер: 469 B |
До Ширина: | Высота: | Размер: 1.2 KiB После Ширина: | Высота: | Размер: 1.2 KiB |
До Ширина: | Высота: | Размер: 2.5 KiB После Ширина: | Высота: | Размер: 2.5 KiB |
До Ширина: | Высота: | Размер: 617 B После Ширина: | Высота: | Размер: 617 B |
До Ширина: | Высота: | Размер: 856 B После Ширина: | Высота: | Размер: 856 B |
До Ширина: | Высота: | Размер: 1.4 KiB После Ширина: | Высота: | Размер: 1.4 KiB |
До Ширина: | Высота: | Размер: 900 B После Ширина: | Высота: | Размер: 900 B |
До Ширина: | Высота: | Размер: 1004 B После Ширина: | Высота: | Размер: 1004 B |
До Ширина: | Высота: | Размер: 1.1 KiB После Ширина: | Высота: | Размер: 1.1 KiB |
До Ширина: | Высота: | Размер: 1.4 KiB После Ширина: | Высота: | Размер: 1.4 KiB |
До Ширина: | Высота: | Размер: 2.6 KiB После Ширина: | Высота: | Размер: 2.6 KiB |
До Ширина: | Высота: | Размер: 1.5 KiB После Ширина: | Высота: | Размер: 1.5 KiB |
До Ширина: | Высота: | Размер: 1.7 KiB После Ширина: | Высота: | Размер: 1.7 KiB |
До Ширина: | Высота: | Размер: 2.0 KiB После Ширина: | Высота: | Размер: 2.0 KiB |
До Ширина: | Высота: | Размер: 3.1 KiB После Ширина: | Высота: | Размер: 3.1 KiB |
До Ширина: | Высота: | Размер: 6.3 KiB После Ширина: | Высота: | Размер: 6.3 KiB |
|
@ -121,26 +121,13 @@
|
|||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\InteractiveSample.cs" />
|
||||
<Compile Include="Helpers\MarkdownHelper.cs" />
|
||||
<Compile Include="Helpers\TitleBarHelper.cs" />
|
||||
<Compile Include="Models\Post.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\FileService.cs" />
|
||||
<Compile Include="Services\IFileService.cs" />
|
||||
<Compile Include="Services\IRedditService.cs" />
|
||||
<Compile Include="Services\ISettingsService.cs" />
|
||||
<Compile Include="Services\SettingsService.cs" />
|
||||
<Compile Include="Shell.xaml.cs">
|
||||
<DependentUpon>Shell.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\AsyncRelayCommandPageViewModel.cs" />
|
||||
<Compile Include="ViewModels\MessengerPageViewModel.cs" />
|
||||
<Compile Include="ViewModels\IocPageViewModel.cs" />
|
||||
<Compile Include="ViewModels\RelayCommandPageViewModel.cs" />
|
||||
<Compile Include="ViewModels\ObservableObjectPageViewModel.cs" />
|
||||
<Compile Include="ViewModels\SamplePageViewModel.cs" />
|
||||
<Compile Include="ViewModels\Widgets\PostWidgetViewModel.cs" />
|
||||
<Compile Include="ViewModels\Widgets\SubredditWidgetViewModel.cs" />
|
||||
<Compile Include="Views\AsyncRelayCommandPage.xaml.cs">
|
||||
<DependentUpon>AsyncRelayCommandPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -265,9 +252,6 @@
|
|||
<PackageReference Include="Microsoft.Toolkit">
|
||||
<Version>7.0.0-build.486</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Toolkit.Mvvm">
|
||||
<Version>7.0.0-build.486</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
|
||||
<Version>7.0.0-build.486</Version>
|
||||
</PackageReference>
|
||||
|
@ -277,18 +261,10 @@
|
|||
<PackageReference Include="Microsoft.UI.Xaml">
|
||||
<Version>2.4.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Nito.AsyncEx.Coordination">
|
||||
<Version>5.1.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="refit">
|
||||
<Version>5.2.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\docs\Introduction.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Controls\InteractiveSample.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
|
@ -364,29 +340,44 @@
|
|||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\docs\AsyncRelayCommand.md">
|
||||
<Content Include="..\MvvmSample.Core\Docs\AsyncRelayCommand.md">
|
||||
<Link>Assets\docs\AsyncRelayCommand.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\docs\Ioc.md">
|
||||
<Content Include="..\MvvmSample.Core\Docs\Introduction.md">
|
||||
<Link>Assets\docs\Introduction.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\docs\Messenger.md">
|
||||
<Content Include="..\MvvmSample.Core\Docs\Ioc.md">
|
||||
<Link>Assets\docs\Ioc.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\docs\ObservableObject.md">
|
||||
<Content Include="..\MvvmSample.Core\Docs\Messenger.md">
|
||||
<Link>Assets\docs\Messenger.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\docs\ObservableRecipient.md">
|
||||
<Content Include="..\MvvmSample.Core\Docs\ObservableObject.md">
|
||||
<Link>Assets\docs\ObservableObject.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\docs\RelayCommand.md">
|
||||
<Content Include="..\MvvmSample.Core\Docs\ObservableRecipient.md">
|
||||
<Link>Assets\docs\ObservableRecipient.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\MvvmSample.Core\Docs\PuttingThingsTogether.md">
|
||||
<Link>Assets\docs\PuttingThingsTogether.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\MvvmSample.Core\Docs\RelayCommand.md">
|
||||
<Link>Assets\docs\RelayCommand.md</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\docs\PuttingThingsTogether.md">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<ProjectReference Include="..\MvvmSample.Core\MvvmSample.Core.csproj">
|
||||
<Project>{28e524f7-61b3-455d-8cbd-615bc4fde814}</Project>
|
||||
<Name>MvvmSample.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
|
@ -2,6 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using MvvmSample.Core.Services;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -23,7 +24,7 @@ namespace MvvmSampleUwp.Services
|
|||
/// <inheritdoc/>
|
||||
public async Task<Stream> OpenForReadAsync(string path)
|
||||
{
|
||||
StorageFile file = await StorageFile.GetFileFromPathAsync(path);
|
||||
StorageFile file = await StorageFile.GetFileFromPathAsync(Path.Combine(InstallationPath, path));
|
||||
|
||||
return await file.OpenStreamForReadAsync();
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using MvvmSample.Core.Services;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:controls="using:MvvmSampleUwp.Controls"
|
||||
xmlns:viewModels="using:MvvmSampleUwp.ViewModels"
|
||||
xmlns:viewModels="using:MvvmSample.Core.ViewModels"
|
||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:viewModels="using:MvvmSampleUwp.ViewModels"
|
||||
xmlns:viewModels="using:MvvmSample.Core.ViewModels"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
mc:Ignorable="d"
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:viewModels="using:MvvmSampleUwp.ViewModels"
|
||||
xmlns:viewModels="using:MvvmSample.Core.ViewModels"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
mc:Ignorable="d"
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:viewModels="using:MvvmSampleUwp.ViewModels"
|
||||
xmlns:viewModels="using:MvvmSample.Core.ViewModels"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
mc:Ignorable="d"
|
||||
|
@ -21,7 +21,7 @@
|
|||
|
||||
<ScrollViewer Padding="16" CanContentRenderOutsideBounds="True">
|
||||
<StackPanel Spacing="16">
|
||||
<toolkit:MarkdownTextBlock Text="{x:Bind ViewModel.GetParagraph('Ioc ([Inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control))'), Mode=OneWay}"/>
|
||||
<toolkit:MarkdownTextBlock Text="{x:Bind ViewModel.GetParagraph('Ioc (Inversion of control)'), Mode=OneWay}"/>
|
||||
<toolkit:MarkdownTextBlock Text="{x:Bind ViewModel.GetParagraph('Configure and resolve services'), Mode=OneWay}"/>
|
||||
<toolkit:MarkdownTextBlock Text="{x:Bind ViewModel.GetParagraph('Constructor injection'), Mode=OneWay}"/>
|
||||
</StackPanel>
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:viewModels="using:MvvmSampleUwp.ViewModels"
|
||||
xmlns:viewModels="using:MvvmSample.Core.ViewModels"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
mc:Ignorable="d"
|
|
@ -6,7 +6,7 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:controls="using:MvvmSampleUwp.Controls"
|
||||
xmlns:viewModels="using:MvvmSampleUwp.ViewModels"
|
||||
xmlns:viewModels="using:MvvmSample.Core.ViewModels"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
mc:Ignorable="d"
|
||||
|
@ -72,7 +72,7 @@ public string Username
|
|||
// Sends a message to request the current username, and updates the property
|
||||
public void RequestCurrentUsername()
|
||||
{
|
||||
Username = Messenger.Default.Send<CurrentUsernameRequestMessage>();
|
||||
Username = WeakReferenceMessenger.Default.Send<CurrentUsernameRequestMessage>();
|
||||
}
|
||||
|
||||
// Resets the current username
|