Update XAML
This commit is contained in:
Родитель
9dd72806f3
Коммит
cacbbfda9e
|
@ -1,5 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<NetVersion>net8.0</NetVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Project>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-ios')) != true">
|
||||
<Compile Remove="**\**\*.ios.cs" />
|
||||
<None Include="**\**\*.ios.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\ios\**\*.cs" />
|
||||
<None Include="**\ios\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-maccatalyst')) != true">
|
||||
<Compile Remove="**\*.macos.cs" />
|
||||
<None Include="**\*.macos.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\macos\**\*.cs" />
|
||||
<None Include="**\macos\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-ios')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-maccatalyst')) != true">
|
||||
<Compile Remove="**\*.macios.cs" />
|
||||
<None Include="**\*.macios.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\macios\**\*.cs" />
|
||||
<None Include="**\macios\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-android')) != true ">
|
||||
<Compile Remove="**\**\*.android.cs" />
|
||||
<None Include="**\**\*.android.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\android\**\*.cs" />
|
||||
<None Include="**\android\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.Contains('-windows')) != true ">
|
||||
<Compile Remove="**\*.windows.cs" />
|
||||
<None Include="**\*.windows.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\windows\**\*.cs" />
|
||||
<None Include="**\windows\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.Contains('-tizen')) != true ">
|
||||
<Compile Remove="**\*.tizen.cs" />
|
||||
<None Include="**\*.tizen.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\tizen\**\*.cs" />
|
||||
<None Include="**\tizen\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="!($(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.EndsWith('.0')) == true AND $(TargetFramework.Contains('-')) != true)"> <!-- e.g net6.0 or net7.0 -->
|
||||
<Compile Remove="**\*.net.cs" />
|
||||
<None Include="**\*.net.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
<Compile Remove="**\net\**\*.cs" />
|
||||
<None Include="**\net\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,221 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.App">
|
||||
<Application.Resources>
|
||||
<Color x:Key="PrimaryColor">#3750D1</Color>
|
||||
<Color x:Key="FrameBackgroundColorDark">#1AFFFFFF</Color>
|
||||
<Color x:Key="BackgroundColorDark">#121212</Color>
|
||||
<Color x:Key="BackgroundColorLight">#EFF2F5</Color>
|
||||
|
||||
<Color x:Key="TextPrimaryColorDark">#FFFFFF</Color>
|
||||
<Color x:Key="TextPrimaryColorLight">#323130</Color>
|
||||
|
||||
<md:DarkMarkdownTheme x:Key="DarkMarkdownTheme" />
|
||||
<md:LightMarkdownTheme x:Key="LightMarkdownTheme" />
|
||||
|
||||
<OnPlatform x:Key="ShellForegroundColorLight"
|
||||
x:TypeArguments="Color">
|
||||
<On Platform="Android"
|
||||
Value="{StaticResource TextPrimaryColorDark}" />
|
||||
<On Platform="iOS"
|
||||
Value="{StaticResource TextPrimaryColorLight}" />
|
||||
</OnPlatform>
|
||||
|
||||
<Style x:Key="BaseStyle"
|
||||
TargetType="Element"
|
||||
ApplyToDerivedTypes="True">
|
||||
<Setter Property="Shell.BackgroundColor"
|
||||
Value="{AppThemeBinding {StaticResource PrimaryColor}}" />
|
||||
<Setter Property="Shell.ForegroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource TextPrimaryColorDark}, Light={StaticResource ShellForegroundColorLight}}" />
|
||||
<Setter Property="Shell.TabBarBackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource BackgroundColorDark}, Light={StaticResource BackgroundColorLight}}" />
|
||||
<Setter Property="Shell.NavBarHasShadow"
|
||||
Value="false" />
|
||||
<Setter Property="Shell.UnselectedColor"
|
||||
Value="Gray" />
|
||||
<Setter Property="Shell.TabBarTitleColor"
|
||||
Value="{StaticResource PrimaryColor}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="TabBar"
|
||||
ApplyToDerivedTypes="True"
|
||||
BasedOn="{StaticResource BaseStyle}" />
|
||||
|
||||
<Style TargetType="FlyoutItem"
|
||||
ApplyToDerivedTypes="True"
|
||||
BasedOn="{StaticResource BaseStyle}">
|
||||
</Style>
|
||||
|
||||
|
||||
<Style BasedOn="{StaticResource BaseStyle}"
|
||||
ApplyToDerivedTypes="True"
|
||||
TargetType="Tab" />
|
||||
|
||||
<Style TargetType="Shell"
|
||||
ApplyToDerivedTypes="True">
|
||||
<Setter Property="FlyoutBackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource BackgroundColorDark}, Light={StaticResource PrimaryColor}}" />
|
||||
</Style>
|
||||
|
||||
|
||||
<Style TargetType="Label"
|
||||
Class="FlyoutItemLabelStyle">
|
||||
<Setter Property="TextColor"
|
||||
Value="{StaticResource TextPrimaryColorDark}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Layout"
|
||||
Class="FlyoutItemLayoutStyle"
|
||||
ApplyToDerivedTypes="True">
|
||||
<Setter Property="BackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource BackgroundColorDark}, Light={StaticResource PrimaryColor}}" />
|
||||
<Setter Property="VisualStateManager.VisualStateGroups">
|
||||
<VisualStateGroupList>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Normal">
|
||||
<VisualState.Setters>
|
||||
<Setter Property="BackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource FrameBackgroundColorDark}, Light={StaticResource PrimaryColor}}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Selected">
|
||||
<VisualState.Setters>
|
||||
<Setter Property="BackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource PrimaryColor}, Light={StaticResource FrameBackgroundColorDark}}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateGroupList>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="md:MarkdownView">
|
||||
<Setter Property="Theme"
|
||||
Value="{AppThemeBinding Dark={StaticResource DarkMarkdownTheme}, Light={StaticResource LightMarkdownTheme}}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Page"
|
||||
ApplyToDerivedTypes="True"
|
||||
BasedOn="{StaticResource BaseStyle}">
|
||||
<Setter Property="BackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource BackgroundColorDark}, Light={StaticResource BackgroundColorLight}}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Label"
|
||||
ApplyToDerivedTypes="True">
|
||||
<Setter Property="TextColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource TextPrimaryColorDark}, Light={StaticResource TextPrimaryColorLight}}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Frame"
|
||||
ApplyToDerivedTypes="True">
|
||||
<Setter Property="BackgroundColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource FrameBackgroundColorDark}, Light={StaticResource BackgroundColorLight}}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="toolkit:TabViewItem">
|
||||
<Setter Property="TextColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource TextPrimaryColorDark}, Light={StaticResource TextPrimaryColorLight}}" />
|
||||
</Style>
|
||||
|
||||
|
||||
<Style TargetType="Picker">
|
||||
<Setter Property="TextColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource TextPrimaryColorDark}, Light={StaticResource TextPrimaryColorLight}}" />
|
||||
</Style>
|
||||
|
||||
<OnPlatform x:Key="FaSolidFont"
|
||||
x:TypeArguments="x:String">
|
||||
<On Platform="iOS"
|
||||
Value="FontAwesome5Free-Solid" />
|
||||
<On Platform="Android"
|
||||
Value="FontAwesomeSolid.otf#Regular" />
|
||||
</OnPlatform>
|
||||
|
||||
<OnPlatform x:Key="FaRegularFont"
|
||||
x:TypeArguments="x:String">
|
||||
<On Platform="iOS"
|
||||
Value="FontAwesome5Free-Regular" />
|
||||
<On Platform="Android"
|
||||
Value="FontAwesomeRegular.otf#Regular" />
|
||||
</OnPlatform>
|
||||
|
||||
<OnPlatform x:Key="FaBrandsFont"
|
||||
x:TypeArguments="x:String">
|
||||
<On Platform="iOS"
|
||||
Value="FontAwesome5Brands-Regular" />
|
||||
<On Platform="Android"
|
||||
Value="FontAwesomeBrands.otf#Regular" />
|
||||
</OnPlatform>
|
||||
|
||||
<FontImage x:Key="PlayIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph=""/>
|
||||
|
||||
<FontImage x:Key="ExchangeIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="CalendarIcon"
|
||||
FontFamily="{StaticResource FaRegularFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="BookIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="FlagIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="CommentIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="SendIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="SortIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="UndoIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="CubeIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="ToolsIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="WrenchIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="GlobeIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="RulerIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="CheckerIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
|
||||
<FontImage x:Key="RefreshIcon"
|
||||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
<toolkit:InvertedBoolConverter x:Key="InvertedBoolConverter" />
|
||||
<toolkit:IsNotNullOrEmptyConverter x:Key="IsNotNullOrEmptyConverter" />
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -1,11 +0,0 @@
|
|||
namespace MvvmSampleMAUI;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public App()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
MainPage = new AppShell();
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
xmlns:views="clr-namespace:MvvmSampleXF.Views"
|
||||
x:Class="MvvmSampleXF.AppShell">
|
||||
<Shell.FlyoutHeader>
|
||||
<controls:FlyoutHeader />
|
||||
</Shell.FlyoutHeader>
|
||||
<ShellContent Title="Introduction"
|
||||
Icon="{StaticResource PlayIcon}"
|
||||
ContentTemplate="{DataTemplate views:IntroductionPage}" />
|
||||
|
||||
<ShellContent Title="ObservableObject"
|
||||
Icon="{StaticResource SortIcon}"
|
||||
ContentTemplate="{DataTemplate views:ObservableObjectPage}" />
|
||||
|
||||
<FlyoutItem Title="Commands"
|
||||
Icon="{StaticResource CalendarIcon}">
|
||||
<ShellContent Title="Introduction"
|
||||
Icon="{StaticResource BookIcon}"
|
||||
ContentTemplate="{DataTemplate views:RelayCommandPage}" />
|
||||
|
||||
<ShellContent Title="Async Commands"
|
||||
Icon="{StaticResource FlagIcon}"
|
||||
ContentTemplate="{DataTemplate views:AsyncRelayCommandPage}" />
|
||||
</FlyoutItem>
|
||||
|
||||
<FlyoutItem Title="Messenger"
|
||||
Icon="{StaticResource CommentIcon}">
|
||||
<ShellContent Title="Introduction"
|
||||
Icon="{StaticResource BookIcon}"
|
||||
ContentTemplate="{DataTemplate views:MessengerPage}" />
|
||||
<ShellContent Title="Sending Messages"
|
||||
Icon="{StaticResource SendIcon}"
|
||||
ContentTemplate="{DataTemplate views:MessengerSendPage}" />
|
||||
<ShellContent Title="Request Messages"
|
||||
Icon="{StaticResource ExchangeIcon}"
|
||||
ContentTemplate="{DataTemplate views:MessengerRequestPage}" />
|
||||
</FlyoutItem>
|
||||
|
||||
<ShellContent Title="Inversion of Control"
|
||||
Icon="{StaticResource UndoIcon}"
|
||||
ContentTemplate="{DataTemplate views:IoCPage}" />
|
||||
|
||||
<ShellContent Title="ViewModel Setup"
|
||||
Icon="{StaticResource CubeIcon}"
|
||||
ContentTemplate="{DataTemplate views:SettingUpTheViewModelsPage}" />
|
||||
|
||||
<FlyoutItem Title="Creating a Service"
|
||||
Icon="{StaticResource ToolsIcon}">
|
||||
<ShellContent Title="Settings Service"
|
||||
Icon="{StaticResource WrenchIcon}"
|
||||
ContentTemplate="{DataTemplate views:SettingsServicePage}" />
|
||||
<ShellContent Title="Reddit Service"
|
||||
Icon="{StaticResource GlobeIcon}"
|
||||
ContentTemplate="{DataTemplate views:RedditServicePage}" />
|
||||
</FlyoutItem>
|
||||
|
||||
<ShellContent Title="Building the UI"
|
||||
Icon="{StaticResource RulerIcon}"
|
||||
ContentTemplate="{DataTemplate views:BuildingTheUIPage}" />
|
||||
|
||||
<ShellContent Title="The Final Result!"
|
||||
Icon="{StaticResource CheckerIcon}"
|
||||
ContentTemplate="{DataTemplate views:RedditBrowserPage}" />
|
||||
</Shell>
|
|
@ -1,10 +0,0 @@
|
|||
namespace MvvmSampleMAUI;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class AppShell : Shell
|
||||
{
|
||||
public AppShell()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="MvvmSampleXF.Controls.FlyoutHeader">
|
||||
<Grid BackgroundColor="{AppThemeBinding Dark=Black, Light=White}">
|
||||
<Image Aspect="AspectFill"
|
||||
Source="headerBg"
|
||||
Opacity="0.6" />
|
||||
</Grid>
|
||||
</ContentView>
|
|
@ -1,10 +0,0 @@
|
|||
namespace MvvmSampleMAUI.Controls;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class FlyoutHeader : ContentView
|
||||
{
|
||||
public FlyoutHeader()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.Controls.InteractiveSample">
|
||||
<ContentView.Resources>
|
||||
<ControlTemplate x:Key="InteractiveSampleTemplate">
|
||||
<Frame CornerRadius="4"
|
||||
BackgroundColor="Transparent"
|
||||
BorderColor="{StaticResource PrimaryColor}">
|
||||
<toolkit:TabView TabIndicatorColor="{StaticResource PrimaryColor}"
|
||||
TabIndicatorPlacement="Bottom">
|
||||
<toolkit:TabViewItem Text="INTERACTIVE SAMPLE"
|
||||
FontAttributes="Bold">
|
||||
<ContentPresenter Padding="12"
|
||||
Content="{TemplateBinding Content}"
|
||||
BindingContext="{TemplateBinding BindingContext}"/>
|
||||
</toolkit:TabViewItem>
|
||||
<toolkit:TabViewItem Text="See XAML">
|
||||
<ScrollView>
|
||||
<md:MarkdownView Padding="8"
|
||||
Markdown="{TemplateBinding XamlCode}" />
|
||||
</ScrollView>
|
||||
</toolkit:TabViewItem>
|
||||
<toolkit:TabViewItem Text="See C#">
|
||||
<ScrollView>
|
||||
<md:MarkdownView Padding="8"
|
||||
Markdown="{TemplateBinding CSharpCode}" />
|
||||
</ScrollView>
|
||||
</toolkit:TabViewItem>
|
||||
</toolkit:TabView>
|
||||
</Frame>
|
||||
</ControlTemplate>
|
||||
</ContentView.Resources>
|
||||
</ContentView>
|
|
@ -1,25 +0,0 @@
|
|||
namespace MvvmSampleMAUI.Controls;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class InteractiveSample : ContentView
|
||||
{
|
||||
public static readonly BindableProperty CSharpCodeProperty = BindableProperty.Create(nameof(CSharpCode), typeof(string), typeof(InteractiveSample), string.Empty);
|
||||
public static readonly BindableProperty XamlCodeProperty = BindableProperty.Create(nameof(XamlCode), typeof(string), typeof(InteractiveSample), string.Empty);
|
||||
|
||||
public InteractiveSample()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public string CSharpCode
|
||||
{
|
||||
get => (string)GetValue(CSharpCodeProperty);
|
||||
set => SetValue(CSharpCodeProperty, value);
|
||||
}
|
||||
|
||||
public string XamlCode
|
||||
{
|
||||
get => (string)GetValue(XamlCodeProperty);
|
||||
set => SetValue(XamlCodeProperty, value);
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
using System.Globalization;
|
||||
namespace MvvmSampleMAUI.Converters;
|
||||
|
||||
public class IsSelfPostToWidthRequestConverter : IValueConverter
|
||||
{
|
||||
public double WidthRequest { get; set; }
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
return str.Equals("self", StringComparison.OrdinalIgnoreCase) ? 0 : WidthRequest;
|
||||
}
|
||||
|
||||
return 0d;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using System.Globalization;
|
||||
namespace MvvmSampleMAUI.Converters;
|
||||
|
||||
public class TaskResultConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Task<string> task)
|
||||
{
|
||||
return task.Status == TaskStatus.RanToCompletion ? task.Result : default;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
using CommunityToolkit.Maui;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.Http.Resilience;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MvvmSample.Core.Services;
|
||||
using MvvmSample.Core.ViewModels;
|
||||
using MvvmSample.Core.ViewModels.Widgets;
|
||||
using MvvmSampleMAUI.Services;
|
||||
using MvvmSampleMAUI.Views;
|
||||
using Polly;
|
||||
using Refit;
|
||||
|
||||
namespace MvvmSampleMAUI;
|
||||
|
||||
public static class MauiProgram
|
||||
{
|
||||
public static MauiApp CreateMauiApp()
|
||||
{
|
||||
var builder = MauiApp.CreateBuilder();
|
||||
builder
|
||||
.UseMauiApp<App>()
|
||||
.UseMauiCommunityToolkit()
|
||||
.ConfigureFonts(fonts =>
|
||||
{
|
||||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
|
||||
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
|
||||
});
|
||||
|
||||
#if DEBUG
|
||||
builder.Logging.AddDebug();
|
||||
#endif
|
||||
builder.Services.AddSingleton<IFilesService, FileService>()
|
||||
.AddSingleton<ISettingsService, SettingsService>()
|
||||
.AddSingleton(RestService.For<IRedditService>("https://www.reddit.com/"))
|
||||
.AddTransientWithShellRoute<AsyncRelayCommandPage, AsyncRelayCommandPageViewModel>()
|
||||
.AddTransientWithShellRoute<BuildingTheUIPage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<IntroductionPage, ObservableObjectPageViewModel>()
|
||||
.AddTransientWithShellRoute<IoCPage, IocPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerRequestPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<ObservableObjectPage, ObservableObjectPageViewModel>()
|
||||
.AddTransientWithShellRoute<PuttingThingsTogetherPage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<RedditBrowserPage>()
|
||||
.AddTransientWithShellRoute<RedditServicePage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<RelayCommandPage, RelayCommandPageViewModel>()
|
||||
.AddTransientWithShellRoute<SettingsServicePage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>();
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
static IServiceCollection AddTransientWithShellRoute<TPage>(this IServiceCollection services) where TPage : ContentPage
|
||||
{
|
||||
Routing.RegisterRoute(AppShell.GetPageRoute<TPage>(), typeof(TPage));
|
||||
return services.AddTransient<TPage>();
|
||||
}
|
||||
|
||||
static IServiceCollection AddTransientWithShellRoute<TPage, TViewModel>(this IServiceCollection services) where TPage : BaseContentPage<TViewModel>
|
||||
where TViewModel : ObservableObject
|
||||
{
|
||||
return services.AddTransientWithShellRoute<TPage, TViewModel>(AppShell.GetPageRoute<TPage>());
|
||||
}
|
||||
|
||||
sealed class MobileHttpRetryStrategyOptions : HttpRetryStrategyOptions
|
||||
{
|
||||
public MobileHttpRetryStrategyOptions()
|
||||
{
|
||||
BackoffType = DelayBackoffType.Exponential;
|
||||
MaxRetryAttempts = 3;
|
||||
UseJitter = true;
|
||||
Delay = TimeSpan.FromSeconds(2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
|
||||
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
|
||||
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
|
||||
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>MvvmSampleMAUI</RootNamespace>
|
||||
<UseMaui>true</UseMaui>
|
||||
<SingleProject>true</SingleProject>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||
|
||||
<!-- Display name -->
|
||||
<ApplicationTitle>MvvmSampleMAUI</ApplicationTitle>
|
||||
|
||||
<!-- App Identifier -->
|
||||
<ApplicationId>com.microsoft.MvvmSample</ApplicationId>
|
||||
|
||||
<!-- Versions -->
|
||||
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>1</ApplicationVersion>
|
||||
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
|
||||
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- App Icon -->
|
||||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4"/>
|
||||
|
||||
<!-- Splash Screen -->
|
||||
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128"/>
|
||||
|
||||
<!-- Images -->
|
||||
<MauiImage Include="Resources\Images\*"/>
|
||||
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185"/>
|
||||
|
||||
<!-- Custom Fonts -->
|
||||
<MauiFont Include="Resources\Fonts\*"/>
|
||||
|
||||
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
|
||||
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.0" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
|
||||
<PackageReference Include="Indiko.Maui.Controls.Markdown" Version="1.0.17"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MvvmSample.Core\MvvmSample.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmSampleMAUI", "MvvmSampleMAUI.csproj", "{29A3122D-D9B1-4A31-B0F3-622B0D97E66C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{29A3122D-D9B1-4A31-B0F3-622B0D97E66C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{29A3122D-D9B1-4A31-B0F3-622B0D97E66C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{29A3122D-D9B1-4A31-B0F3-622B0D97E66C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{29A3122D-D9B1-4A31-B0F3-622B0D97E66C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C0E44466-2824-4633-8595-21FA2B608433}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,31 +0,0 @@
|
|||
using System.Reflection;
|
||||
using MvvmSample.Core.Services;
|
||||
|
||||
namespace MvvmSampleMAUI.Services;
|
||||
|
||||
public sealed class FileService : IFilesService
|
||||
{
|
||||
public string InstallationPath => Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
|
||||
public Task<Stream> OpenForReadAsync(string path)
|
||||
{
|
||||
if (GetType() is not Type type)
|
||||
{
|
||||
throw new InvalidOperationException("Could not retrieve type");
|
||||
}
|
||||
|
||||
return GetEmbeddedFileStreamAsync(type, path);
|
||||
}
|
||||
|
||||
|
||||
static async Task<Stream> GetEmbeddedFileStreamAsync(Type assemblyType, string fileName)
|
||||
{
|
||||
var manifestName = assemblyType.GetTypeInfo().Assembly
|
||||
.GetManifestResourceNames()
|
||||
.FirstOrDefault(n => n.EndsWith(fileName.Replace(" ", "_").Replace("\\", ".").Replace("/", "."), StringComparison.OrdinalIgnoreCase))
|
||||
?? throw new InvalidOperationException($"Failed to find resource [{fileName}]");
|
||||
|
||||
return await Task.FromResult(assemblyType.GetTypeInfo().Assembly.GetManifestResourceStream(manifestName) ?? Stream.Null)
|
||||
.ConfigureAwait(ConfigureAwaitOptions.ForceYielding | ConfigureAwaitOptions.None);
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using MvvmSample.Core.Services;
|
||||
|
||||
namespace MvvmSampleMAUI.Services;
|
||||
|
||||
public sealed class SettingsService(IPreferences preferences) : ISettingsService
|
||||
{
|
||||
readonly IPreferences _preferences = preferences;
|
||||
|
||||
public T? GetValue<T>(string key) => _preferences.Get<T?>(key, default);
|
||||
|
||||
public void SetValue<T>(string key, T? value) => _preferences.Set(key, value);
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
xmlns:converters="clr-namespace:MvvmSampleXF.Converters"
|
||||
x:Class="MvvmSampleXF.Views.AsyncRelayCommandPage"
|
||||
x:DataType="vm:AsyncRelayCommandPageViewModel"
|
||||
Title="Commands">
|
||||
<ContentPage.Resources>
|
||||
<converters:TaskResultConverter x:Key="TaskResultConverter" />
|
||||
</ContentPage.Resources>
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[AsyncRelayCommand and AsyncRelayCommand<T>], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How they work], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Working with asynchronous commands], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask.Status, TargetNullValue='Task status: ', FallbackValue='Task status: ', StringFormat='Task status: {0}' }" />
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, StringFormat='Result: {0}' }" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding DownloadTextCommand}" />
|
||||
<ActivityIndicator HorizontalOptions="Center"
|
||||
IsVisible="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}"
|
||||
IsRunning="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<ContentPage.Resources>
|
||||
<converters:TaskResultConverter x:Key="TaskResultConverter" />
|
||||
</ContentPage.Resources>
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask.Status, TargetNullValue='Task status: ', FallbackValue='Task status: ', StringFormat='Task status: {0}' }" />
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, StringFormat='Result: {0}' }" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding DownloadTextCommand}" />
|
||||
<ActivityIndicator HorizontalOptions="Center"
|
||||
IsVisible="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}"
|
||||
IsRunning="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public MyViewModel()
|
||||
{
|
||||
DownloadTextCommand = new AsyncRelayCommand(DownloadTextAsync);
|
||||
}
|
||||
|
||||
public IAsyncRelayCommand DownloadTextCommand { get; }
|
||||
|
||||
private async Task<string> DownloadTextAsync()
|
||||
{
|
||||
await Task.Delay(3000); // Simulate a web request
|
||||
|
||||
return "Hello world!";
|
||||
}
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,20 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class AsyncRelayCommandPage : BaseContentPage<AsyncRelayCommandPageViewModel>
|
||||
{
|
||||
public AsyncRelayCommandPage(AsyncRelayCommandPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("AsyncRelayCommand");
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.Views.BuildingTheUIPage"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
Title="Building the UI">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Building the UI], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Good to go! 🚀], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,19 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class BuildingTheUIPage : BaseContentPage<SamplePageViewModel>
|
||||
{
|
||||
public BuildingTheUIPage(SamplePageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("PuttingThingsTogether");
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.Views.IntroductionPage"
|
||||
x:DataType="vm:ObservableObjectPageViewModel"
|
||||
Title="Introduction">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Introduction to the MVVM package], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[When should I use this package?], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,20 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class IntroductionPage : BaseContentPage<ObservableObjectPageViewModel>
|
||||
{
|
||||
public IntroductionPage(ObservableObjectPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("Introduction");
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.Views.IoCPage"
|
||||
x:DataType="vm:IocPageViewModel"
|
||||
Title="Inversion of Control">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Ioc (Inversion of control)], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Configure and resolve services], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Constructor injection], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,22 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class IoCPage : BaseContentPage<IocPageViewModel>
|
||||
{
|
||||
public IoCPage(IocPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public IocPageViewModel ViewModel => (IocPageViewModel)BindingContext;
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
ViewModel.LoadDocsCommand.Execute("IoC");
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.Views.MessengerPage"
|
||||
x:DataType="vm:MessengerPageViewModel"
|
||||
Title="Messenger">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Messenger], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How it works], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,20 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MessengerPage : BaseContentPage<MessengerPageViewModel>
|
||||
{
|
||||
public MessengerPage(MessengerPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("Messenger");
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
x:Class="MvvmSampleXF.Views.MessengerRequestPage"
|
||||
Title="Messenger">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Sending and receiving messages], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="500">
|
||||
<StackLayout Spacing="8">
|
||||
|
||||
<Label Text="{Binding Username, Mode=OneWay}" />
|
||||
<Button Text="Click to request the username!"
|
||||
Command="{Binding RequestCurrentUsernameCommand}" />
|
||||
<Button Text="Click to reset the local username!"
|
||||
Command="{Binding ResetCurrentUsernameCommand}" />
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
|
||||
<Label Text="{Binding Username, Mode=OneWay}" />
|
||||
<Button Text="Click to request the username!"
|
||||
Command="{Binding RequestCurrentUsernameCommand}" />
|
||||
<Button Text="Click to reset the local username!"
|
||||
Command="{Binding ResetCurrentUsernameCommand}" />
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class UserSenderViewModel : ObservableRecipient
|
||||
{
|
||||
public UserSenderViewModel()
|
||||
{
|
||||
SendUserMessageCommand = new RelayCommand(SendUserMessage);
|
||||
}
|
||||
|
||||
public ICommand SendUserMessageCommand { get; }
|
||||
|
||||
private string username = "Bob";
|
||||
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<CurrentUsernameRequestMessage>(this, m => m.Reply(Username));
|
||||
}
|
||||
|
||||
public void SendUserMessage()
|
||||
{
|
||||
Username = Username == "Bob" ? "Alice" : "Bob";
|
||||
|
||||
Messenger.Send(new UsernameChangedMessage(Username));
|
||||
}
|
||||
}
|
||||
|
||||
// A sample request message to get the current username
|
||||
public sealed class CurrentUsernameRequestMessage : RequestMessage<string>
|
||||
{
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,29 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MessengerRequestPage : BaseContentPage<MessengerPageViewModel>
|
||||
{
|
||||
public MessengerRequestPage(MessengerPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("Messenger");
|
||||
BindingContext.SenderViewModel.IsActive = true;
|
||||
BindingContext.ReceiverViewModel.IsActive = true;
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
|
||||
ViewModel.SenderViewModel.IsActive = false;
|
||||
ViewModel.ReceiverViewModel.IsActive = false;
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
x:Class="MvvmSampleXF.Views.MessengerSendPage"
|
||||
x:DataType="vm:MessengerPageViewModel"
|
||||
Title="Messenger">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Sending and receiving messages], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="600">
|
||||
<StackLayout Spacing="8">
|
||||
|
||||
<!--Sender module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding SenderViewModel.Username, Mode=OneWay}" />
|
||||
<Button Text="Click to send a message!"
|
||||
Command="{Binding SenderViewModel.SendUserMessageCommand}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
|
||||
<!--Receiver module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding ReceiverViewModel.Username, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
|
||||
<!--Sender module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding SenderViewModel.Username, Mode=OneWay}" />
|
||||
<Button Text="Click to send a message!"
|
||||
Command="{Binding SenderViewModel.SendUserMessageCommand}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
|
||||
<!--Receiver module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding ReceiverViewModel.Username, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
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();
|
||||
|
||||
// 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
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<CurrentUsernameRequestMessage>(this, m => m.Reply(Username));
|
||||
}
|
||||
|
||||
public void SendUserMessage()
|
||||
{
|
||||
Username = Username == "Bob" ? "Alice" : "Bob";
|
||||
|
||||
Messenger.Send(new UsernameChangedMessage(Username));
|
||||
}
|
||||
}
|
||||
|
||||
// Simple viewmodel for a module receiving a username message
|
||||
public class UserReceiverViewModel : ObservableRecipient
|
||||
{
|
||||
private string username = "";
|
||||
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<UsernameChangedMessage>(this, m => Username = m.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// A sample message with a username value
|
||||
public sealed class UsernameChangedMessage : ValueChangedMessage<string>
|
||||
{
|
||||
public UsernameChangedMessage(string value) : base(value)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,29 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MessengerSendPage : BaseContentPage<MessengerPageViewModel>
|
||||
{
|
||||
public MessengerSendPage(MessengerPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("Messenger");
|
||||
BindingContext.SenderViewModel.IsActive = true;
|
||||
BindingContext.ReceiverViewModel.IsActive = true;
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
|
||||
BindingContext.SenderViewModel.IsActive = false;
|
||||
BindingContext.ReceiverViewModel.IsActive = false;
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
x:Class="MvvmSampleXF.Views.ObservableObjectPage"
|
||||
x:DataType="vm:ObservableObjectPageViewModel"
|
||||
Title="ObservableObject">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[ObservableObject], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How it works], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Simple property], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="300">
|
||||
<StackLayout Spacing="8">
|
||||
<!--Simple property sample-->
|
||||
<Entry Placeholder="Type here to update the text below"
|
||||
Text="{Binding Name, Mode=TwoWay}" />
|
||||
<Label Text="{Binding Name, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<!--Simple property sample-->
|
||||
<Entry Placeholder="Type here to update the text below"
|
||||
Text="{Binding Name, Mode=TwoWay}" />
|
||||
<Label Text="{Binding Name, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name to display.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => SetProperty(ref name, value);
|
||||
}
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
|
||||
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Wrapping a non-observable model], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Handling `Task<T>` properties], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<StackLayout Spacing="8">
|
||||
<Button Text="Click me to load a Task to await"
|
||||
Command="{Binding ReloadTaskCommand}" />
|
||||
<Label Text="{Binding MyTask.Status, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Button Text="Click me to load a Task to await"
|
||||
Command="{Binding ReloadTaskCommand}" />
|
||||
<Label Text="{Binding MyTask.Status, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public ObservableObjectPageViewModel()
|
||||
{
|
||||
ReloadTaskCommand = new RelayCommand(ReloadTask);
|
||||
}
|
||||
|
||||
public ICommand ReloadTaskCommand { get; }
|
||||
|
||||
private string name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => SetProperty(ref name, value);
|
||||
}
|
||||
|
||||
private TaskNotifier myTask;
|
||||
|
||||
public Task MyTask
|
||||
{
|
||||
get => myTask;
|
||||
private set => SetPropertyAndNotifyOnCompletion(ref myTask, value);
|
||||
}
|
||||
|
||||
public void ReloadTask()
|
||||
{
|
||||
MyTask = Task.Delay(3000);
|
||||
}
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,19 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class ObservableObjectPage : BaseContentPage<ObservableObjectPageViewModel>
|
||||
{
|
||||
public ObservableObjectPage(ObservableObjectPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("ObservableObject");
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:Class="MvvmSampleXF.Views.PuttingThingsTogetherPage"
|
||||
x:DataType="vm:SamplePageViewModel">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Spacing="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Putting things together], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[What do we want to build], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,20 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class PuttingThingsTogetherPage : BaseContentPage<SamplePageViewModel>
|
||||
{
|
||||
public PuttingThingsTogetherPage(SamplePageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("PuttingThingsTogether");
|
||||
}
|
||||
}
|
|
@ -1,254 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:widgets="clr-namespace:MvvmSampleXF.Views.Widgets"
|
||||
x:Class="MvvmSampleXF.Views.RedditBrowserPage"
|
||||
Title="The Final Result!">
|
||||
<Grid Padding="16">
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}">
|
||||
<toolkit:TabView x:Name="RedditTabView"
|
||||
TabIndicatorPlacement="Bottom"
|
||||
TabIndicatorColor="Orange"
|
||||
IsSwipeEnabled="False">
|
||||
<toolkit:TabViewItem Text="Subreddit">
|
||||
<widgets:SubredditWidget x:Name="SubredditWidget" />
|
||||
</toolkit:TabViewItem>
|
||||
<toolkit:TabViewItem Text="Post">
|
||||
<widgets:PostWidget x:Name="PostWidget" />
|
||||
</toolkit:TabViewItem>
|
||||
</toolkit:TabView>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
|
||||
```xml
|
||||
<!--Feed-->
|
||||
<Grid RowDefinitions="60, 8, *">
|
||||
|
||||
<!--Header with topic selector and refresh button-->
|
||||
<Frame Padding="10,0,10,0">
|
||||
<Grid ColumnDefinitions="*, Auto">
|
||||
<Picker ItemsSource="{Binding Subreddits, Mode=OneWay}"
|
||||
SelectedItem="{Binding SelectedSubreddit, Mode=TwoWay}"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="StartAndExpand">
|
||||
<Picker.Behaviors>
|
||||
<toolkit:EventToCommandBehavior EventName="SelectedIndexChanged"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Picker.Behaviors>
|
||||
</Picker>
|
||||
<Button Text="Refresh"
|
||||
Grid.Column="1"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Grid>
|
||||
</Frame>
|
||||
|
||||
<!--Items list-->
|
||||
<CollectionView Grid.Row="2"
|
||||
ItemsSource="{Binding Posts}"
|
||||
SelectedItem="{Binding SelectedPost, Mode=TwoWay}"
|
||||
SelectionMode="Single"
|
||||
SelectionChanged="CollectionView_SelectionChanged"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay, Converter={StaticResource InvertedBoolConverter}}">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Post">
|
||||
<Frame BorderColor="Black">
|
||||
<Grid ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Title}"
|
||||
FontSize="15"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Thumbnail}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
|
||||
<!--Loading bar-->
|
||||
<ActivityIndicator Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Margin="0, 10, 0, 0"
|
||||
VerticalOptions="Start"
|
||||
IsRunning="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}" />
|
||||
</Grid>
|
||||
|
||||
<!--Post-->
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
|
||||
<!--Self text-->
|
||||
<Frame Grid.Row="1">
|
||||
<ScrollView>
|
||||
<Label Text="{Binding Post.SelfText, Mode=OneWay}"
|
||||
LineBreakMode="WordWrap"
|
||||
Margin="16" />
|
||||
</ScrollView>
|
||||
</Frame>
|
||||
|
||||
<!--Header-->
|
||||
<Frame>
|
||||
<Grid Grid.Row="0"
|
||||
ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Post.Title, Mode=OneWay}"
|
||||
FontSize="16"
|
||||
FontAttributes="Bold"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Post.Thumbnail, Mode=OneWay}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Post.Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Frame>
|
||||
</Grid>
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// A viewmodel for a subreddit widget.
|
||||
/// </summary>
|
||||
public sealed class SubredditWidgetViewModel : ObservableRecipient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IRedditService"/> instance to use.
|
||||
/// </summary>
|
||||
private readonly IRedditService RedditService = Ioc.Default.GetRequiredService<IRedditService>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ISettingsService"/> instance to use.
|
||||
/// </summary>
|
||||
private readonly ISettingsService SettingsService = Ioc.Default.GetRequiredService<ISettingsService>();
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="AsyncLock"/> instance to avoid concurrent requests.
|
||||
/// </summary>
|
||||
private readonly AsyncLock LoadingLock = new AsyncLock();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SubredditWidgetViewModel"/> instance.
|
||||
/// </summary>
|
||||
public SubredditWidgetViewModel()
|
||||
{
|
||||
LoadPostsCommand = new AsyncRelayCommand(LoadPostsAsync);
|
||||
|
||||
selectedSubreddit = SettingsService.GetValue<string>(nameof(SelectedSubreddit)) ?? Subreddits[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IAsyncRelayCommand"/> instance responsible for loading posts.
|
||||
/// </summary>
|
||||
public IAsyncRelayCommand LoadPostsCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of loaded posts.
|
||||
/// </summary>
|
||||
public ObservableCollection<Post> Posts { get; } = new ObservableCollection<Post>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of available subreddits to pick from.
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Subreddits { get; } = new[]
|
||||
{
|
||||
"microsoft",
|
||||
"windows",
|
||||
"surface",
|
||||
"windowsphone",
|
||||
"dotnet",
|
||||
"csharp"
|
||||
};
|
||||
|
||||
private string selectedSubreddit;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected subreddit.
|
||||
/// </summary>
|
||||
public string SelectedSubreddit
|
||||
{
|
||||
get => selectedSubreddit;
|
||||
set
|
||||
{
|
||||
SetProperty(ref selectedSubreddit, value);
|
||||
|
||||
SettingsService.SetValue(nameof(SelectedSubreddit), value);
|
||||
}
|
||||
}
|
||||
|
||||
private Post selectedPost;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected subreddit.
|
||||
/// </summary>
|
||||
public Post SelectedPost
|
||||
{
|
||||
get => selectedPost;
|
||||
set => SetProperty(ref selectedPost, value, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the posts from a specified subreddit.
|
||||
/// </summary>
|
||||
private async Task LoadPostsAsync()
|
||||
{
|
||||
using (await LoadingLock.LockAsync())
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await RedditService.GetSubredditPostsAsync(SelectedSubreddit);
|
||||
|
||||
Posts.Clear();
|
||||
|
||||
foreach (var item in response.Data.Items)
|
||||
{
|
||||
Posts.Add(item.Data);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Whoops!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A viewmodel for a post widget.
|
||||
/// </summary>
|
||||
public sealed class PostWidgetViewModel : ObservableRecipient, IRecipient<PropertyChangedMessage<Post>>
|
||||
{
|
||||
private Post post;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently selected post, if any.
|
||||
/// </summary>
|
||||
public Post Post
|
||||
{
|
||||
get => post;
|
||||
private set => SetProperty(ref post, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Receive(PropertyChangedMessage<Post> message)
|
||||
{
|
||||
if (message.Sender.GetType() == typeof(SubredditWidgetViewModel) &&
|
||||
message.PropertyName == nameof(SubredditWidgetViewModel.SelectedPost))
|
||||
{
|
||||
Post = message.NewValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</Grid>
|
||||
</ContentPage>
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class RedditBrowserPage : ContentPage
|
||||
{
|
||||
public RedditBrowserPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
SubredditWidget.PostSelected += HandleSubredditWidgetPostSelected;
|
||||
PostWidget.OnAppearing();
|
||||
SubredditWidget.OnAppearing();
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
SubredditWidget.PostSelected -= HandleSubredditWidgetPostSelected;
|
||||
PostWidget.OnDisappearing();
|
||||
}
|
||||
|
||||
void HandleSubredditWidgetPostSelected(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
//Ugly workaround for https://github.com/xamarin/XamarinCommunityToolkit/issues/595
|
||||
// MethodInfo dynMethod = RedditTabView.GetType().GetMethod("UpdateSelectedIndex", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
// dynMethod?.Invoke(RedditTabView, [1, false]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
x:Class="MvvmSampleXF.Views.RedditServicePage"
|
||||
Title="Creating a Service">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
Markdown="{Binding Path=Texts[Building the Reddit service], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,18 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class RedditServicePage : BaseContentPage<SamplePageViewModel>
|
||||
{
|
||||
public RedditServicePage(SamplePageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
BindingContext.LoadDocsCommand.Execute("PuttingThingsTogether");
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:controls="clr-namespace:MvvmSampleXF.Controls"
|
||||
x:Class="MvvmSampleXF.Views.RelayCommandPage"
|
||||
x:DataType="vm:RelayCommandPageViewModel"
|
||||
Title="Commands">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Spacing="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[RelayCommand], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How they work], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Working with `ICommand`], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding Counter}"/>
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding IncrementCounterCommand}" />
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding Counter}"/>
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding IncrementCounterCommand}" />
|
||||
</StackLayout>
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class MyViewModel : ObservableObject
|
||||
{
|
||||
public MyViewModel()
|
||||
{
|
||||
IncrementCounterCommand = new RelayCommand(IncrementCounter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ICommand"/> responsible for incrementing <see cref="Counter"/>.
|
||||
/// </summary>
|
||||
public ICommand IncrementCounterCommand { get; }
|
||||
|
||||
private int counter;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value of the counter.
|
||||
/// </summary>
|
||||
public int Counter
|
||||
{
|
||||
get => counter;
|
||||
private set => SetProperty(ref counter, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increments <see cref="Counter"/>.
|
||||
/// </summary>
|
||||
private void IncrementCounter() => Counter++;
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,19 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class RelayCommandPage : BaseContentPage<RelayCommandPageViewModel>
|
||||
{
|
||||
public RelayCommandPage(RelayCommandPageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("RelayCommand");
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="MvvmSampleXF.Views.SettingUpTheViewModelsPage"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
Title="ViewModel Setup">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
Markdown="{Binding Path=Texts[Building the settings service], Mode=OneWay}"/>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,19 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SettingUpTheViewModelsPage : BaseContentPage<SamplePageViewModel>
|
||||
{
|
||||
public SettingUpTheViewModelsPage(SamplePageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("PuttingThingsTogether");
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="MvvmSampleXF.Views.SettingsServicePage"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
Title="Creating a Service">
|
||||
<ScrollView Padding="16">
|
||||
<StackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
Markdown="{Binding Path=Texts[Building the settings service], Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage>
|
|
@ -1,19 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SettingsServicePage : BaseContentPage<SamplePageViewModel>
|
||||
{
|
||||
public SettingsServicePage(SamplePageViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
BindingContext.LoadDocsCommand.Execute("PuttingThingsTogether");
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:widgets="clr-namespace:MvvmSample.Core.ViewModels.Widgets;assembly=MvvmSample.Core"
|
||||
xmlns:converters="clr-namespace:MvvmSampleXF.Converters"
|
||||
x:Class="MvvmSampleXF.Views.Widgets.PostWidget">
|
||||
<ContentView.Resources>
|
||||
<converters:IsSelfPostToWidthRequestConverter WidthRequest="160"
|
||||
x:Key="IsSelfPostToWidthRequestConverter" />
|
||||
</ContentView.Resources>
|
||||
<!--Post-->
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
|
||||
<!--Self text-->
|
||||
<Frame Grid.Row="1">
|
||||
<ScrollView>
|
||||
<Label Text="{Binding Post.SelfText, Mode=OneWay}"
|
||||
LineBreakMode="WordWrap"
|
||||
Margin="16" />
|
||||
</ScrollView>
|
||||
</Frame>
|
||||
|
||||
<!--Header-->
|
||||
<Frame>
|
||||
<Grid Grid.Row="0"
|
||||
ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Post.Title, Mode=OneWay}"
|
||||
FontSize="16"
|
||||
FontAttributes="Bold"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Post.Thumbnail, Mode=OneWay}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Post.Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Frame>
|
||||
</Grid>
|
||||
</ContentView>
|
|
@ -1,31 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels.Widgets;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace MvvmSampleMAUI.Views.Widgets
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class PostWidget : ContentView
|
||||
{
|
||||
public PostWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = Ioc.Default.GetRequiredService<PostWidgetViewModel>();
|
||||
}
|
||||
|
||||
public PostWidgetViewModel ViewModel => (PostWidgetViewModel)BindingContext;
|
||||
|
||||
public void OnAppearing()
|
||||
{
|
||||
ViewModel.IsActive = true;
|
||||
}
|
||||
|
||||
public void OnDisappearing()
|
||||
{
|
||||
ViewModel.IsActive = false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:models="clr-namespace:MvvmSample.Core.Models;assembly=MvvmSample.Core"
|
||||
xmlns:widgets="clr-namespace:MvvmSample.Core.ViewModels.Widgets;assembly=MvvmSample.Core"
|
||||
xmlns:converters="clr-namespace:MvvmSampleXF.Converters"
|
||||
x:Class="MvvmSampleXF.Views.Widgets.SubredditWidget">
|
||||
<ContentView.Resources>
|
||||
<converters:IsSelfPostToWidthRequestConverter WidthRequest="120"
|
||||
x:Key="IsSelfPostToWidthRequestConverter" />
|
||||
</ContentView.Resources>
|
||||
<!--Feed-->
|
||||
<Grid RowDefinitions="60, 8, *">
|
||||
|
||||
<!--Header with topic selector and refresh button-->
|
||||
<Frame Padding="10,0,10,0">
|
||||
<Grid ColumnDefinitions="*, Auto">
|
||||
<Picker ItemsSource="{Binding Subreddits, Mode=OneWay}"
|
||||
SelectedItem="{Binding SelectedSubreddit, Mode=TwoWay}"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
Title="Subreddit">
|
||||
<Picker.Behaviors>
|
||||
<toolkit:EventToCommandBehavior EventName="SelectedIndexChanged"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Picker.Behaviors>
|
||||
</Picker>
|
||||
<Button Text="Refresh"
|
||||
Grid.Column="1"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Grid>
|
||||
</Frame>
|
||||
|
||||
<!--Items list-->
|
||||
<CollectionView Grid.Row="2"
|
||||
ItemsSource="{Binding Posts}"
|
||||
SelectedItem="{Binding SelectedPost, Mode=TwoWay}"
|
||||
SelectionMode="Single"
|
||||
SelectionChanged="CollectionView_SelectionChanged"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay, Converter={StaticResource InvertedBoolConverter}}">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Post">
|
||||
<Frame BorderColor="Black">
|
||||
<Grid ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Title}"
|
||||
FontSize="15"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Thumbnail}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
|
||||
<!--Loading bar-->
|
||||
<ActivityIndicator Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Margin="0, 10, 0, 0"
|
||||
VerticalOptions="Start"
|
||||
IsRunning="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</ContentView>
|
|
@ -1,33 +0,0 @@
|
|||
using MvvmSample.Core.ViewModels.Widgets;
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace MvvmSampleMAUI.Views.Widgets
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SubredditWidget : ContentView
|
||||
{
|
||||
public event EventHandler PostSelected;
|
||||
public SubredditWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = Ioc.Default.GetRequiredService<SubredditWidgetViewModel>();
|
||||
}
|
||||
|
||||
public SubredditWidgetViewModel ViewModel => (SubredditWidgetViewModel)BindingContext;
|
||||
|
||||
private void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
PostSelected?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void OnAppearing()
|
||||
{
|
||||
ViewModel.LoadPostsCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F02FAF9-B9BD-405B-8987-51540C89ED18}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Directory.Build.props = Directory.Build.props
|
||||
Directory.Build.targets = Directory.Build.targets
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmSample.Core", "MvvmSample.Core\MvvmSample.Core.csproj", "{770388CB-6068-4201-89B6-CA131B1DC59D}"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
x:Class="MvvmSampleMAUI.App">
|
||||
<Application.Resources>
|
||||
<Color x:Key="PrimaryColor">#3750D1</Color>
|
||||
|
@ -13,9 +13,6 @@
|
|||
<Color x:Key="TextPrimaryColorDark">#FFFFFF</Color>
|
||||
<Color x:Key="TextPrimaryColorLight">#323130</Color>
|
||||
|
||||
<md:DarkMarkdownTheme x:Key="DarkMarkdownTheme" />
|
||||
<md:LightMarkdownTheme x:Key="LightMarkdownTheme" />
|
||||
|
||||
<OnPlatform x:Key="ShellForegroundColorLight"
|
||||
x:TypeArguments="Color">
|
||||
<On Platform="Android"
|
||||
|
@ -93,11 +90,6 @@
|
|||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="md:MarkdownView">
|
||||
<Setter Property="Theme"
|
||||
Value="{AppThemeBinding Dark={StaticResource DarkMarkdownTheme}, Light={StaticResource LightMarkdownTheme}}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Page"
|
||||
ApplyToDerivedTypes="True"
|
||||
BasedOn="{StaticResource BaseStyle}">
|
||||
|
@ -117,11 +109,6 @@
|
|||
Value="{AppThemeBinding Dark={StaticResource FrameBackgroundColorDark}, Light={StaticResource BackgroundColorLight}}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="toolkit:TabViewItem">
|
||||
<Setter Property="TextColor"
|
||||
Value="{AppThemeBinding Dark={StaticResource TextPrimaryColorDark}, Light={StaticResource TextPrimaryColorLight}}" />
|
||||
</Style>
|
||||
|
||||
|
||||
<Style TargetType="Picker">
|
||||
<Setter Property="TextColor"
|
||||
|
@ -216,6 +203,5 @@
|
|||
FontFamily="{StaticResource FaSolidFont}"
|
||||
Glyph="" />
|
||||
<toolkit:InvertedBoolConverter x:Key="InvertedBoolConverter" />
|
||||
<toolkit:IsNotNullOrEmptyConverter x:Key="IsNotNullOrEmptyConverter" />
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -2,34 +2,13 @@
|
|||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
x:Class="MvvmSampleMAUI.Controls.InteractiveSample">
|
||||
<ContentView.Resources>
|
||||
<ControlTemplate x:Key="InteractiveSampleTemplate">
|
||||
<Border CornerRadius="4"
|
||||
BackgroundColor="Transparent"
|
||||
BorderColor="{StaticResource PrimaryColor}">
|
||||
<toolkit:TabView TabIndicatorColor="{StaticResource PrimaryColor}"
|
||||
TabIndicatorPlacement="Bottom">
|
||||
<toolkit:TabViewItem Text="INTERACTIVE SAMPLE"
|
||||
FontAttributes="Bold">
|
||||
<ContentPresenter Padding="12"
|
||||
Content="{TemplateBinding Content}"
|
||||
BindingContext="{TemplateBinding BindingContext}"/>
|
||||
</toolkit:TabViewItem>
|
||||
<toolkit:TabViewItem Text="See XAML">
|
||||
<ScrollView>
|
||||
<md:MarkdownView Padding="8"
|
||||
Markdown="{TemplateBinding XamlCode}" />
|
||||
</ScrollView>
|
||||
</toolkit:TabViewItem>
|
||||
<toolkit:TabViewItem Text="See C#">
|
||||
<ScrollView>
|
||||
<md:MarkdownView Padding="8"
|
||||
Markdown="{TemplateBinding CSharpCode}" />
|
||||
</ScrollView>
|
||||
</toolkit:TabViewItem>
|
||||
</toolkit:TabView>
|
||||
<Border StrokeShape="RoundRectangle 4,4,4,4"
|
||||
BackgroundColor="Transparent"
|
||||
Stroke="{StaticResource PrimaryColor}">
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</ContentView.Resources>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using CommunityToolkit.Maui;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.Http.Resilience;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MvvmSample.Core.Services;
|
||||
using MvvmSample.Core.ViewModels;
|
||||
using MvvmSample.Core.ViewModels.Widgets;
|
||||
using MvvmSampleMAUI.Controls;
|
||||
using MvvmSampleMAUI.Services;
|
||||
using MvvmSampleMAUI.Views;
|
||||
using Polly;
|
||||
|
@ -16,8 +16,7 @@ public static class MauiProgram
|
|||
{
|
||||
public static MauiApp CreateMauiApp()
|
||||
{
|
||||
var builder = MauiApp.CreateBuilder();
|
||||
builder
|
||||
var builder = MauiApp.CreateBuilder()
|
||||
.UseMauiApp<App>()
|
||||
.UseMauiCommunityToolkit()
|
||||
.ConfigureFonts(fonts =>
|
||||
|
@ -31,39 +30,47 @@ public static class MauiProgram
|
|||
#endif
|
||||
builder.Services.AddSingleton<IFilesService, FileService>()
|
||||
.AddSingleton<ISettingsService, SettingsService>()
|
||||
.AddSingleton(RestService.For<IRedditService>("https://www.reddit.com/"))
|
||||
.AddTransientWithShellRoute<AsyncRelayCommandPage, AsyncRelayCommandPageViewModel>()
|
||||
.AddTransientWithShellRoute<BuildingTheUIPage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<IntroductionPage, ObservableObjectPageViewModel>()
|
||||
.AddTransientWithShellRoute<IoCPage, IocPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerRequestPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<ObservableObjectPage, ObservableObjectPageViewModel>()
|
||||
.AddTransientWithShellRoute<PuttingThingsTogetherPage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<RedditBrowserPage>()
|
||||
.AddTransientWithShellRoute<RedditServicePage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<RelayCommandPage, RelayCommandPageViewModel>()
|
||||
.AddTransientWithShellRoute<SettingsServicePage, SamplePageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>()
|
||||
.AddTransientWithShellRoute<MessengerSendPage, MessengerPageViewModel>();
|
||||
.AddRefitClient<IRedditService>()
|
||||
.ConfigureHttpClient(static client => client.BaseAddress = new Uri("https://www.reddit.com"))
|
||||
.AddStandardResilienceHandler(static options => options.Retry = new MobileHttpRetryStrategyOptions());
|
||||
|
||||
RegisterViews(builder.Services);
|
||||
RegisterViewModels(builder.Services);
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
static IServiceCollection AddTransientWithShellRoute<TPage>(this IServiceCollection services) where TPage : ContentPage
|
||||
static void RegisterViews(in IServiceCollection services)
|
||||
{
|
||||
Routing.RegisterRoute(AppShell.GetPageRoute<TPage>(), typeof(TPage));
|
||||
return services.AddTransient<TPage>();
|
||||
services.AddTransient<AsyncRelayCommandPage>()
|
||||
.AddTransient<BuildingTheUIPage>()
|
||||
.AddTransient<FlyoutHeader>()
|
||||
.AddTransient<InteractiveSample>()
|
||||
.AddTransient<IntroductionPage>()
|
||||
.AddTransient<IoCPage>()
|
||||
.AddTransient<MessengerPage>()
|
||||
.AddTransient<MessengerRequestPage>()
|
||||
.AddTransient<MessengerSendPage>()
|
||||
.AddTransient<ObservableObjectPage>()
|
||||
.AddTransient<PuttingThingsTogetherPage>()
|
||||
.AddTransient<RedditBrowserPage>()
|
||||
.AddTransient<RedditServicePage>()
|
||||
.AddTransient<RelayCommandPage>()
|
||||
.AddTransient<SettingsServicePage>();
|
||||
}
|
||||
|
||||
static IServiceCollection AddTransientWithShellRoute<TPage, TViewModel>(this IServiceCollection services) where TPage : BaseContentPage<TViewModel>
|
||||
where TViewModel : ObservableObject
|
||||
static void RegisterViewModels(in IServiceCollection services)
|
||||
{
|
||||
return services.AddTransientWithShellRoute<TPage, TViewModel>(AppShell.GetPageRoute<TPage>());
|
||||
services.AddTransient<AsyncRelayCommandPageViewModel>()
|
||||
.AddTransient<ContactsListWidgetViewModel>()
|
||||
.AddTransient<IocPageViewModel>()
|
||||
.AddTransient<MessengerPageViewModel>()
|
||||
.AddTransient<ObservableObjectPageViewModel>()
|
||||
.AddTransient<PostWidgetViewModel>()
|
||||
.AddTransient<RelayCommandPageViewModel>()
|
||||
.AddTransient<SamplePageViewModel>()
|
||||
.AddTransient<SubredditWidgetViewModel>()
|
||||
.AddTransient<ValidationFormWidgetViewModel>();
|
||||
}
|
||||
|
||||
sealed class MobileHttpRetryStrategyOptions : HttpRetryStrategyOptions
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
|
||||
<TargetFrameworks>$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
|
||||
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
|
||||
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
|
||||
<!-- <TargetFrameworks>$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks> -->
|
||||
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>MvvmSampleMAUI</RootNamespace>
|
||||
|
@ -55,10 +55,22 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
|
||||
<PackageReference Include="Indiko.Maui.Controls.Markdown" Version="1.0.17"/>
|
||||
<PackageReference Include="Refit.HttpClientFactory" Version="7.2.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MvvmSample.Core\MvvmSample.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\AsyncRelayCommand.md" Link="Resources\raw\AsyncRelayCommand.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\Index.md" Link="Resources\raw\Introduction.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\Ioc.md" Link="Resources\raw\Ioc.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\Messenger.md" Link="Resources\raw\Messenger.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\ObservableObject.md" Link="Resources\raw\ObservableObject.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\ObservableRecipient.md" Link="Resources\raw\ObservableRecipient.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\PuttingThingsTogether.md" Link="Resources\raw\PuttingThingsTogether.md" />
|
||||
<EmbeddedResource Include="..\..\msdocs-communitytoolkit\docs\mvvm\RelayCommand.md" Link="Resources\raw\RelayCommand.md" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,71 +1,75 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
xmlns:converters="clr-namespace:MvvmSampleMAUI.Converters"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:TypeArguments="vm:AsyncRelayCommandPageViewModel"
|
||||
x:Class="MvvmSampleMAUI.Views.AsyncRelayCommandPage"
|
||||
x:DataType="vm:AsyncRelayCommandPageViewModel"
|
||||
Title="Commands">
|
||||
<ContentPage.Resources>
|
||||
<converters:TaskResultConverter x:Key="TaskResultConverter" />
|
||||
</ContentPage.Resources>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[AsyncRelayCommand and AsyncRelayCommand<T>], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How they work], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Working with asynchronous commands], Mode=OneWay}" />
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask.Status, TargetNullValue='Task status: ', FallbackValue='Task status: ', StringFormat='Task status: {0}' }" />
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, StringFormat='Result: {0}' }" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding DownloadTextCommand}" />
|
||||
<ActivityIndicator HorizontalOptions="Center"
|
||||
IsVisible="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}"
|
||||
IsRunning="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<ContentPage.Resources>
|
||||
<converters:TaskResultConverter x:Key="TaskResultConverter" />
|
||||
</ContentPage.Resources>
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask.Status, TargetNullValue='Task status: ', FallbackValue='Task status: ', StringFormat='Task status: {0}' }" />
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, StringFormat='Result: {0}' }" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding DownloadTextCommand}" />
|
||||
<ActivityIndicator HorizontalOptions="Center"
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
xmlns:converters="clr-namespace:MvvmSampleMAUI.Converters"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.AsyncRelayCommandPage"
|
||||
x:TypeArguments="vm:AsyncRelayCommandPageViewModel"
|
||||
x:DataType="vm:AsyncRelayCommandPageViewModel"
|
||||
Title="Commands">
|
||||
<ContentPage.Resources>
|
||||
<converters:TaskResultConverter x:Key="TaskResultConverter" />
|
||||
</ContentPage.Resources>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView
|
||||
MarkdownText="{Binding Path=Texts[AsyncRelayCommand and AsyncRelayCommand<T>], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[How they work], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Working with asynchronous commands], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label
|
||||
Text="{Binding DownloadTextCommand.ExecutionTask.Status, TargetNullValue='Task status: ', FallbackValue='Task status: ', StringFormat='Task status: {0}' }" />
|
||||
<Label
|
||||
Text="{Binding DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, StringFormat='Result: {0}' }" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding DownloadTextCommand}" />
|
||||
<ActivityIndicator HorizontalOptions="Center"
|
||||
IsVisible="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}"
|
||||
IsRunning="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<ContentPage.Resources>
|
||||
<converters:TaskResultConverter x:Key="TaskResultConverter" />
|
||||
</ContentPage.Resources>
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask.Status, TargetNullValue='Task status: ', FallbackValue='Task status: ', StringFormat='Task status: {0}' }" />
|
||||
<Label Text="{Binding DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, StringFormat='Result: {0}' }" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding DownloadTextCommand}" />
|
||||
<ActivityIndicator HorizontalOptions="Center"
|
||||
IsVisible="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}"
|
||||
IsRunning="{Binding DownloadTextCommand.IsRunning, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public MyViewModel()
|
||||
{
|
||||
DownloadTextCommand = new AsyncRelayCommand(DownloadTextAsync);
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public MyViewModel()
|
||||
{
|
||||
DownloadTextCommand = new AsyncRelayCommand(DownloadTextAsync);
|
||||
}
|
||||
|
||||
public IAsyncRelayCommand DownloadTextCommand { get; }
|
||||
public IAsyncRelayCommand DownloadTextCommand { get; }
|
||||
|
||||
private async Task<string> DownloadTextAsync()
|
||||
{
|
||||
await Task.Delay(3000); // Simulate a web request
|
||||
private async Task<string> DownloadTextAsync()
|
||||
{
|
||||
await Task.Delay(3000); // Simulate a web request
|
||||
|
||||
return "Hello world!";
|
||||
}
|
||||
return "Hello world!";
|
||||
}
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.BuildingTheUIPage"
|
||||
x:TypeArguments="vm:AsyncRelayCommandPageViewModel"
|
||||
x:TypeArguments="vm:SamplePageViewModel"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
Title="Building the UI">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Building the UI], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Good to go! 🚀], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Building the UI], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Good to go! 🚀], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.IntroductionPage"
|
||||
x:TypeArguments="vm:AsyncRelayCommandPageViewModel"
|
||||
x:TypeArguments="vm:ObservableObjectPageViewModel"
|
||||
x:DataType="vm:ObservableObjectPageViewModel"
|
||||
Title="Introduction">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Introduction to the MVVM package], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[When should I use this package?], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Introduction to the MVVM package], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[When should I use this package?], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,18 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:TypeArguments="vm:IocPageViewModel"
|
||||
x:Class="MvvmSampleMAUI.Views.IoCPage"
|
||||
x:DataType="vm:IocPageViewModel"
|
||||
Title="Inversion of Control">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Ioc (Inversion of control)], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Configure and resolve services], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Constructor injection], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Ioc (Inversion of control)], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Configure and resolve services], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Constructor injection], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.MessengerPage"
|
||||
x:TypeArguments="vm:MessengerPageViewModel"
|
||||
x:DataType="vm:MessengerPageViewModel"
|
||||
Title="Messenger">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Messenger], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How it works], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Messenger], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[How it works], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,82 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:TypeArguments="vm:MessengerPageViewModel"
|
||||
x:DataType="vm:MessengerPageViewModel"
|
||||
x:Class="MvvmSampleMAUI.Views.MessengerRequestPage"
|
||||
Title="Messenger">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Sending and receiving messages], Mode=OneWay}" />
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Sending and receiving messages], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="500">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="500">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
|
||||
<Label Text="{Binding Username, Mode=OneWay}" />
|
||||
<Button Text="Click to request the username!"
|
||||
Command="{Binding RequestCurrentUsernameCommand}" />
|
||||
<Button Text="Click to reset the local username!"
|
||||
Command="{Binding ResetCurrentUsernameCommand}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding Username, Mode=OneWay}" />
|
||||
<Button Text="Click to request the username!"
|
||||
Command="{Binding RequestCurrentUsernameCommand}" />
|
||||
<Button Text="Click to reset the local username!"
|
||||
Command="{Binding ResetCurrentUsernameCommand}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
|
||||
<Label Text="{Binding Username, Mode=OneWay}" />
|
||||
<Button Text="Click to request the username!"
|
||||
Command="{Binding RequestCurrentUsernameCommand}" />
|
||||
<Button Text="Click to reset the local username!"
|
||||
Command="{Binding ResetCurrentUsernameCommand}" />
|
||||
</StackLayout>
|
||||
<Label Text="{Binding Username, Mode=OneWay}" />
|
||||
<Button Text="Click to request the username!"
|
||||
Command="{Binding RequestCurrentUsernameCommand}" />
|
||||
<Button Text="Click to reset the local username!"
|
||||
Command="{Binding ResetCurrentUsernameCommand}" />
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class UserSenderViewModel : ObservableRecipient
|
||||
{
|
||||
public UserSenderViewModel()
|
||||
{
|
||||
SendUserMessageCommand = new RelayCommand(SendUserMessage);
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class UserSenderViewModel : ObservableRecipient
|
||||
{
|
||||
public UserSenderViewModel()
|
||||
{
|
||||
SendUserMessageCommand = new RelayCommand(SendUserMessage);
|
||||
}
|
||||
|
||||
public ICommand SendUserMessageCommand { get; }
|
||||
public ICommand SendUserMessageCommand { get; }
|
||||
|
||||
private string username = "Bob";
|
||||
private string username = "Bob";
|
||||
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<CurrentUsernameRequestMessage>(this, m => m.Reply(Username));
|
||||
}
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<CurrentUsernameRequestMessage>(this, m => m.Reply(Username));
|
||||
}
|
||||
|
||||
public void SendUserMessage()
|
||||
{
|
||||
Username = Username == "Bob" ? "Alice" : "Bob";
|
||||
public void SendUserMessage()
|
||||
{
|
||||
Username = Username == "Bob" ? "Alice" : "Bob";
|
||||
|
||||
Messenger.Send(new UsernameChangedMessage(Username));
|
||||
}
|
||||
}
|
||||
Messenger.Send(new UsernameChangedMessage(Username));
|
||||
}
|
||||
}
|
||||
|
||||
// A sample request message to get the current username
|
||||
public sealed class CurrentUsernameRequestMessage : RequestMessage<string>
|
||||
{
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
// A sample request message to get the current username
|
||||
public sealed class CurrentUsernameRequestMessage : RequestMessage<string>
|
||||
{
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -23,7 +23,7 @@ public partial class MessengerRequestPage : BaseContentPage<MessengerPageViewMod
|
|||
{
|
||||
base.OnDisappearing();
|
||||
|
||||
ViewModel.SenderViewModel.IsActive = false;
|
||||
ViewModel.ReceiverViewModel.IsActive = false;
|
||||
BindingContext.SenderViewModel.IsActive = false;
|
||||
BindingContext.ReceiverViewModel.IsActive = false;
|
||||
}
|
||||
}
|
|
@ -1,147 +1,148 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.MessengerSendPage"
|
||||
x:TypeArguments="vm:MessengerPageViewModel"
|
||||
x:DataType="vm:MessengerPageViewModel"
|
||||
Title="Messenger">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Sending and receiving messages], Mode=OneWay}" />
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Sending and receiving messages], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="600">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="600">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
|
||||
<!--Sender module-->
|
||||
<Border BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding SenderViewModel.Username, Mode=OneWay}" />
|
||||
<Button Text="Click to send a message!"
|
||||
Command="{Binding SenderViewModel.SendUserMessageCommand}" />
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
<!--Sender module-->
|
||||
<Border Stroke="#40FFFFFF"
|
||||
StrokeShape="RoundRectangle 4,4,4,4"
|
||||
Padding="8">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding SenderViewModel.Username, Mode=OneWay}" />
|
||||
<Button Text="Click to send a message!"
|
||||
Command="{Binding SenderViewModel.SendUserMessageCommand}" />
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
|
||||
<!--Receiver module-->
|
||||
<Border BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding ReceiverViewModel.Username, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<!--Receiver module-->
|
||||
<Border Stroke="#40FFFFFF"
|
||||
StrokeShape="RoundRectangle 4,4,4,4"
|
||||
Padding="8">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding ReceiverViewModel.Username, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
|
||||
<!--Sender module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding SenderViewModel.Username, Mode=OneWay}" />
|
||||
<Button Text="Click to send a message!"
|
||||
<!--Sender module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding SenderViewModel.Username, Mode=OneWay}" />
|
||||
<Button Text="Click to send a message!"
|
||||
Command="{Binding SenderViewModel.SendUserMessageCommand}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
|
||||
<!--Receiver module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding ReceiverViewModel.Username, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
<!--Receiver module-->
|
||||
<Frame BorderColor="#40FFFFFF"
|
||||
CornerRadius="4"
|
||||
Padding="8">
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding ReceiverViewModel.Username, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class MessengerPageViewModel : SamplePageViewModel
|
||||
{
|
||||
public MessengerPageViewModel()
|
||||
{
|
||||
RequestCurrentUsernameCommand = new RelayCommand(RequestCurrentUsername);
|
||||
ResetCurrentUsernameCommand = new RelayCommand(ResetCurrentUsername);
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class MessengerPageViewModel : SamplePageViewModel
|
||||
{
|
||||
public MessengerPageViewModel()
|
||||
{
|
||||
RequestCurrentUsernameCommand = new RelayCommand(RequestCurrentUsername);
|
||||
ResetCurrentUsernameCommand = new RelayCommand(ResetCurrentUsername);
|
||||
}
|
||||
|
||||
public ICommand RequestCurrentUsernameCommand { get; }
|
||||
public ICommand ResetCurrentUsernameCommand { get; }
|
||||
public ICommand RequestCurrentUsernameCommand { get; }
|
||||
public ICommand ResetCurrentUsernameCommand { get; }
|
||||
|
||||
public UserSenderViewModel SenderViewModel { get; } = new UserSenderViewModel();
|
||||
public UserSenderViewModel SenderViewModel { get; } = new UserSenderViewModel();
|
||||
|
||||
public UserReceiverViewModel ReceiverViewModel { get; } = new UserReceiverViewModel();
|
||||
public UserReceiverViewModel ReceiverViewModel { get; } = new UserReceiverViewModel();
|
||||
|
||||
// Simple viewmodel for a module sending a username message
|
||||
public class UserSenderViewModel : ObservableRecipient
|
||||
{
|
||||
public UserSenderViewModel()
|
||||
{
|
||||
SendUserMessageCommand = new RelayCommand(SendUserMessage);
|
||||
}
|
||||
// Simple viewmodel for a module sending a username message
|
||||
public class UserSenderViewModel : ObservableRecipient
|
||||
{
|
||||
public UserSenderViewModel()
|
||||
{
|
||||
SendUserMessageCommand = new RelayCommand(SendUserMessage);
|
||||
}
|
||||
|
||||
public ICommand SendUserMessageCommand { get; }
|
||||
public ICommand SendUserMessageCommand { get; }
|
||||
|
||||
private string username = "Bob";
|
||||
private string username = "Bob";
|
||||
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<CurrentUsernameRequestMessage>(this, m => m.Reply(Username));
|
||||
}
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<CurrentUsernameRequestMessage>(this, m => m.Reply(Username));
|
||||
}
|
||||
|
||||
public void SendUserMessage()
|
||||
{
|
||||
Username = Username == "Bob" ? "Alice" : "Bob";
|
||||
public void SendUserMessage()
|
||||
{
|
||||
Username = Username == "Bob" ? "Alice" : "Bob";
|
||||
|
||||
Messenger.Send(new UsernameChangedMessage(Username));
|
||||
}
|
||||
}
|
||||
Messenger.Send(new UsernameChangedMessage(Username));
|
||||
}
|
||||
}
|
||||
|
||||
// Simple viewmodel for a module receiving a username message
|
||||
public class UserReceiverViewModel : ObservableRecipient
|
||||
{
|
||||
private string username = "";
|
||||
// Simple viewmodel for a module receiving a username message
|
||||
public class UserReceiverViewModel : ObservableRecipient
|
||||
{
|
||||
private string username = "";
|
||||
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
public string Username
|
||||
{
|
||||
get => username;
|
||||
private set => SetProperty(ref username, value);
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<UsernameChangedMessage>(this, m => Username = m.Value);
|
||||
}
|
||||
}
|
||||
protected override void OnActivated()
|
||||
{
|
||||
Messenger.Register
|
||||
<UsernameChangedMessage>(this, m => Username = m.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// A sample message with a username value
|
||||
public sealed class UsernameChangedMessage : ValueChangedMessage<string>
|
||||
{
|
||||
public UsernameChangedMessage(string value) : base(value)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
// A sample message with a username value
|
||||
public sealed class UsernameChangedMessage : ValueChangedMessage<string>
|
||||
{
|
||||
public UsernameChangedMessage(string value) : base(value)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,111 +1,111 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:TypeArguments="vm:ObservableObjectPageViewModel"
|
||||
x:Class="MvvmSampleMAUI.Views.ObservableObjectPage"
|
||||
x:DataType="vm:ObservableObjectPageViewModel"
|
||||
Title="ObservableObject">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[ObservableObject], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How it works], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Simple property], Mode=OneWay}" />
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Padding="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[ObservableObject], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[How it works], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Simple property], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="300">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<!--Simple property sample-->
|
||||
<Entry Placeholder="Type here to update the text below"
|
||||
Text="{Binding Name, Mode=TwoWay}" />
|
||||
<Label Text="{Binding Name, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<!--Simple property sample-->
|
||||
<Entry Placeholder="Type here to update the text below"
|
||||
Text="{Binding Name, Mode=TwoWay}" />
|
||||
<Label Text="{Binding Name, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="300">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<!--Simple property sample-->
|
||||
<Entry Placeholder="Type here to update the text below"
|
||||
Text="{Binding Name, Mode=TwoWay}" />
|
||||
<Label Text="{Binding Name, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<!--Simple property sample-->
|
||||
<Entry Placeholder="Type here to update the text below"
|
||||
Text="{Binding Name, Mode=TwoWay}" />
|
||||
<Label Text="{Binding Name, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
private string name;
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name to display.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => SetProperty(ref name, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the name to display.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => SetProperty(ref name, value);
|
||||
}
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Wrapping a non-observable model], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Handling `Task<T>` properties], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Button Text="Click me to load a Task to await"
|
||||
Command="{Binding ReloadTaskCommand}" />
|
||||
<Label Text="{Binding MyTask.Status, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Button Text="Click me to load a Task to await"
|
||||
Command="{Binding ReloadTaskCommand}" />
|
||||
<Label Text="{Binding MyTask.Status, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Wrapping a non-observable model], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Handling `Task<T>` properties], Mode=OneWay}" />
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public ObservableObjectPageViewModel()
|
||||
{
|
||||
ReloadTaskCommand = new RelayCommand(ReloadTask);
|
||||
}
|
||||
|
||||
public ICommand ReloadTaskCommand { get; }
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Button Text="Click me to load a Task to await"
|
||||
Command="{Binding ReloadTaskCommand}" />
|
||||
<Label Text="{Binding MyTask.Status, Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Button Text="Click me to load a Task to await"
|
||||
Command="{Binding ReloadTaskCommand}" />
|
||||
<Label Text="{Binding MyTask.Status, Mode=OneWay}" />
|
||||
</StackLayout>
|
||||
|
||||
private string name;
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public ObservableObjectPageViewModel()
|
||||
{
|
||||
ReloadTaskCommand = new RelayCommand(ReloadTask);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => SetProperty(ref name, value);
|
||||
}
|
||||
public ICommand ReloadTaskCommand { get; }
|
||||
|
||||
private TaskNotifier myTask;
|
||||
private string name;
|
||||
|
||||
public Task MyTask
|
||||
{
|
||||
get => myTask;
|
||||
private set => SetPropertyAndNotifyOnCompletion(ref myTask, value);
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => SetProperty(ref name, value);
|
||||
}
|
||||
|
||||
public void ReloadTask()
|
||||
{
|
||||
MyTask = Task.Delay(3000);
|
||||
}
|
||||
private TaskNotifier myTask;
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
public Task MyTask
|
||||
{
|
||||
get => myTask;
|
||||
private set => SetPropertyAndNotifyOnCompletion(ref myTask, value);
|
||||
}
|
||||
|
||||
public void ReloadTask()
|
||||
{
|
||||
MyTask = Task.Delay(3000);
|
||||
}
|
||||
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,16 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.PuttingThingsTogetherPage"
|
||||
x:TypeArguments="vm:SamplePageViewModel"
|
||||
x:DataType="vm:SamplePageViewModel">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Putting things together], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[What do we want to build], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Putting things together], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[What do we want to build], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
|
@ -6,20 +7,15 @@
|
|||
xmlns:widgets="clr-namespace:MvvmSampleMAUI.Views.Widgets"
|
||||
x:Class="MvvmSampleMAUI.Views.RedditBrowserPage"
|
||||
Title="The Final Result!">
|
||||
<Grid Padding="16">
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}">
|
||||
<toolkit:TabView x:Name="RedditTabView"
|
||||
TabIndicatorPlacement="Bottom"
|
||||
TabIndicatorColor="Orange"
|
||||
IsSwipeEnabled="False">
|
||||
<toolkit:TabViewItem Text="Subreddit">
|
||||
<widgets:SubredditWidget x:Name="SubredditWidget" />
|
||||
</toolkit:TabViewItem>
|
||||
<toolkit:TabViewItem Text="Post">
|
||||
<widgets:PostWidget x:Name="PostWidget" />
|
||||
</toolkit:TabViewItem>
|
||||
</toolkit:TabView>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
<VerticalStackLayout Padding="16" Spacing="24">
|
||||
<Label Text="XAML Code"
|
||||
FontSize="24"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
VerticalTextAlignment="Center"
|
||||
HorizontalTextAlignment="Center"/>
|
||||
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
|
||||
```xml
|
||||
<!--Feed-->
|
||||
|
@ -112,8 +108,16 @@
|
|||
</Frame>
|
||||
</Grid>
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
|
||||
<Label Text="XAML Code"
|
||||
FontSize="24"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
VerticalTextAlignment="Center"
|
||||
HorizontalTextAlignment="Center"/>
|
||||
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// A viewmodel for a subreddit widget.
|
||||
|
@ -248,7 +252,6 @@ public sealed class PostWidgetViewModel : ObservableRecipient, IRecipient<Pro
|
|||
}
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</Grid>
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class RedditBrowserPage : ContentPage
|
||||
|
@ -11,28 +8,4 @@ public partial class RedditBrowserPage : ContentPage
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
SubredditWidget.PostSelected += HandleSubredditWidgetPostSelected;
|
||||
PostWidget.OnAppearing();
|
||||
SubredditWidget.OnAppearing();
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
SubredditWidget.PostSelected -= HandleSubredditWidgetPostSelected;
|
||||
PostWidget.OnDisappearing();
|
||||
}
|
||||
|
||||
void HandleSubredditWidgetPostSelected(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
//Ugly workaround for https://github.com/xamarin/XamarinCommunityToolkit/issues/595
|
||||
// MethodInfo dynMethod = RedditTabView.GetType().GetMethod("UpdateSelectedIndex", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
// dynMethod?.Invoke(RedditTabView, [1, false]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:Class="MvvmSampleMAUI.Views.RedditServicePage"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
x:TypeArguments="vm:SamplePageViewModel"
|
||||
Title="Creating a Service">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
Markdown="{Binding Path=Texts[Building the Reddit service], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
MarkdownText="{Binding Path=Texts[Building the Reddit service], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:controls="clr-namespace:MvvmSampleMAUI.Controls"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
|
@ -9,61 +10,61 @@
|
|||
x:TypeArguments="vm:RelayCommandPageViewModel"
|
||||
x:DataType="vm:RelayCommandPageViewModel"
|
||||
Title="Commands">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[RelayCommand], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[How they work], Mode=OneWay}" />
|
||||
<md:MarkdownView Markdown="{Binding Path=Texts[Working with `ICommand`], Mode=OneWay}" />
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[RelayCommand], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[How they work], Mode=OneWay}" />
|
||||
<md:MarkdownView MarkdownText="{Binding Path=Texts[Working with `ICommand`], Mode=OneWay}" />
|
||||
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding Counter}"/>
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding IncrementCounterCommand}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding Counter}"/>
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding IncrementCounterCommand}" />
|
||||
</StackLayout>
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class MyViewModel : ObservableObject
|
||||
{
|
||||
public MyViewModel()
|
||||
{
|
||||
IncrementCounterCommand = new RelayCommand(IncrementCounter);
|
||||
}
|
||||
<controls:InteractiveSample ControlTemplate="{StaticResource InteractiveSampleTemplate}"
|
||||
HeightRequest="400">
|
||||
<VerticalStackLayout Spacing="8">
|
||||
<Label Text="{Binding Counter}" />
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding IncrementCounterCommand}" />
|
||||
</VerticalStackLayout>
|
||||
<controls:InteractiveSample.XamlCode>
|
||||
```xml
|
||||
<StackLayout Spacing="8">
|
||||
<Label Text="{Binding Counter}"/>
|
||||
<Button Text="Click me!"
|
||||
Command="{Binding IncrementCounterCommand}" />
|
||||
</StackLayout>
|
||||
```
|
||||
</controls:InteractiveSample.XamlCode>
|
||||
<controls:InteractiveSample.CSharpCode>
|
||||
```csharp
|
||||
public class MyViewModel : ObservableObject
|
||||
{
|
||||
public MyViewModel()
|
||||
{
|
||||
IncrementCounterCommand = new RelayCommand(IncrementCounter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ICommand"/> responsible for incrementing <see cref="Counter"/>.
|
||||
/// </summary>
|
||||
public ICommand IncrementCounterCommand { get; }
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ICommand"/> responsible for incrementing <see cref="Counter"/>.
|
||||
/// </summary>
|
||||
public ICommand IncrementCounterCommand { get; }
|
||||
|
||||
private int counter;
|
||||
private int counter;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value of the counter.
|
||||
/// </summary>
|
||||
public int Counter
|
||||
{
|
||||
get => counter;
|
||||
private set => SetProperty(ref counter, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current value of the counter.
|
||||
/// </summary>
|
||||
public int Counter
|
||||
{
|
||||
get => counter;
|
||||
private set => SetProperty(ref counter, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increments <see cref="Counter"/>.
|
||||
/// </summary>
|
||||
private void IncrementCounter() => Counter++;
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
/// <summary>
|
||||
/// Increments <see cref="Counter"/>.
|
||||
/// </summary>
|
||||
private void IncrementCounter() => Counter++;
|
||||
}
|
||||
```
|
||||
</controls:InteractiveSample.CSharpCode>
|
||||
</controls:InteractiveSample>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:TypeArguments="vm:SamplePageViewModel"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
x:Class="MvvmSampleMAUI.Views.SettingUpTheViewModelsPage"
|
||||
Title="ViewModel Setup">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
Markdown="{Binding Path=Texts[Building the settings service], Mode=OneWay}"/>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
MarkdownText="{Binding Path=Texts[Building the settings service], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<views:BaseContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="MvvmSampleMAUI.Views.SettingsServicePage"
|
||||
xmlns:vm="clr-namespace:MvvmSample.Core.ViewModels;assembly=MvvmSample.Core"
|
||||
xmlns:md="clr-namespace:Xam.Forms.Markdown;assembly=Xam.Forms.MarkdownView"
|
||||
xmlns:md="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
|
||||
xmlns:views="clr-namespace:MvvmSampleMAUI.Views"
|
||||
x:TypeArguments="vm:SamplePageViewModel"
|
||||
x:DataType="vm:SamplePageViewModel"
|
||||
Title="Creating a Service">
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
Markdown="{Binding Path=Texts[Building the settings service], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<ScrollView Padding="16">
|
||||
<VerticalStackLayout Spacing="16">
|
||||
<md:MarkdownView x:Name="Markdown"
|
||||
MarkdownText="{Binding Path=Texts[Building the settings service], Mode=OneWay}" />
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</views:BaseContentPage>
|
|
@ -1,9 +1,9 @@
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
namespace MvvmSampleMAUI.Views;
|
||||
namespace MvvmSampleMAUI.Views.Widgets;
|
||||
|
||||
public abstract class BaseContentPage<TViewModel> : ContentPage where TViewModel : ObservableObject
|
||||
public abstract class BaseContentView<TViewModel> : ContentView where TViewModel : ObservableObject
|
||||
{
|
||||
protected BaseContentPage(TViewModel viewModel)
|
||||
protected BaseContentView(TViewModel viewModel)
|
||||
{
|
||||
base.BindingContext = viewModel;
|
||||
}
|
|
@ -1,42 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:widgets="clr-namespace:MvvmSample.Core.ViewModels.Widgets;assembly=MvvmSample.Core"
|
||||
xmlns:converters="clr-namespace:MvvmSampleMAUI.Converters"
|
||||
x:Class="MvvmSampleMAUI.Views.Widgets.PostWidget">
|
||||
<ContentView.Resources>
|
||||
<converters:IsSelfPostToWidthRequestConverter WidthRequest="160"
|
||||
x:Key="IsSelfPostToWidthRequestConverter" />
|
||||
</ContentView.Resources>
|
||||
<!--Post-->
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
|
||||
<!--Self text-->
|
||||
<Border Grid.Row="1">
|
||||
<ScrollView>
|
||||
<Label Text="{Binding Post.SelfText, Mode=OneWay}"
|
||||
LineBreakMode="WordWrap"
|
||||
Margin="16" />
|
||||
</ScrollView>
|
||||
</Border>
|
||||
<mauiWidgets:BaseContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:widgets="clr-namespace:MvvmSample.Core.ViewModels.Widgets;assembly=MvvmSample.Core"
|
||||
xmlns:converters="clr-namespace:MvvmSampleMAUI.Converters"
|
||||
xmlns:mauiWidgets="clr-namespace:MvvmSampleMAUI.Views.Widgets"
|
||||
x:Class="MvvmSampleMAUI.Views.Widgets.PostWidget"
|
||||
x:TypeArguments="widgets:PostWidgetViewModel"
|
||||
x:DataType="widgets:PostWidgetViewModel">
|
||||
<ContentView.Resources>
|
||||
<converters:IsSelfPostToWidthRequestConverter WidthRequest="160"
|
||||
x:Key="IsSelfPostToWidthRequestConverter" />
|
||||
</ContentView.Resources>
|
||||
<!--Post-->
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
|
||||
<!--Header-->
|
||||
<Border>
|
||||
<Grid Grid.Row="0"
|
||||
ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Post.Title, Mode=OneWay}"
|
||||
FontSize="16"
|
||||
FontAttributes="Bold"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Post.Thumbnail, Mode=OneWay}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Post.Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ContentView>
|
||||
<!--Self text-->
|
||||
<Border Grid.Row="1">
|
||||
<ScrollView>
|
||||
<Label Text="{Binding Post.SelfText, Mode=OneWay}"
|
||||
LineBreakMode="WordWrap"
|
||||
Margin="16" />
|
||||
</ScrollView>
|
||||
</Border>
|
||||
|
||||
<!--Header-->
|
||||
<Border>
|
||||
<Grid Grid.Row="0"
|
||||
ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Post.Title, Mode=OneWay}"
|
||||
FontSize="16"
|
||||
FontAttributes="Bold"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Post.Thumbnail, Mode=OneWay}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Post.Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</mauiWidgets:BaseContentView>
|
|
@ -1,31 +1,25 @@
|
|||
using MvvmSample.Core.ViewModels.Widgets;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
namespace MvvmSampleMAUI.Views.Widgets;
|
||||
|
||||
namespace MvvmSampleMAUI.Views.Widgets
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class PostWidget : BaseContentView<PostWidgetViewModel>
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class PostWidget : ContentView
|
||||
public PostWidget(PostWidgetViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
public PostWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = Ioc.Default.GetRequiredService<PostWidgetViewModel>();
|
||||
}
|
||||
Loaded += HandleLoaded;
|
||||
Unloaded += HandleUnloaded;
|
||||
}
|
||||
|
||||
public PostWidgetViewModel ViewModel => (PostWidgetViewModel)BindingContext;
|
||||
|
||||
public void OnAppearing()
|
||||
{
|
||||
ViewModel.IsActive = true;
|
||||
}
|
||||
|
||||
public void OnDisappearing()
|
||||
{
|
||||
ViewModel.IsActive = false;
|
||||
}
|
||||
void HandleLoaded(object? sender, EventArgs e)
|
||||
{
|
||||
BindingContext.IsActive = true;
|
||||
}
|
||||
|
||||
void HandleUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
BindingContext.IsActive = false;
|
||||
}
|
||||
}
|
|
@ -1,71 +1,75 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:models="clr-namespace:MvvmSample.Core.Models;assembly=MvvmSample.Core"
|
||||
xmlns:widgets="clr-namespace:MvvmSample.Core.ViewModels.Widgets;assembly=MvvmSample.Core"
|
||||
xmlns:converters="clr-namespace:MvvmSampleMAUI.Converters"
|
||||
x:Class="MvvmSampleMAUI.Views.Widgets.SubredditWidget">
|
||||
<ContentView.Resources>
|
||||
<converters:IsSelfPostToWidthRequestConverter WidthRequest="120"
|
||||
x:Key="IsSelfPostToWidthRequestConverter" />
|
||||
</ContentView.Resources>
|
||||
<!--Feed-->
|
||||
<Grid RowDefinitions="60, 8, *">
|
||||
|
||||
<!--Header with topic selector and refresh button-->
|
||||
<Border Padding="10,0,10,0">
|
||||
<Grid ColumnDefinitions="*, Auto">
|
||||
<Picker ItemsSource="{Binding Subreddits, Mode=OneWay}"
|
||||
SelectedItem="{Binding SelectedSubreddit, Mode=TwoWay}"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
Title="Subreddit">
|
||||
<Picker.Behaviors>
|
||||
<toolkit:EventToCommandBehavior EventName="SelectedIndexChanged"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Picker.Behaviors>
|
||||
</Picker>
|
||||
<Button Text="Refresh"
|
||||
Grid.Column="1"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<mauiWidgets:BaseContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
|
||||
xmlns:models="clr-namespace:MvvmSample.Core.Models;assembly=MvvmSample.Core"
|
||||
xmlns:widgets="clr-namespace:MvvmSample.Core.ViewModels.Widgets;assembly=MvvmSample.Core"
|
||||
xmlns:mauiWidgets="clr-namespace:MvvmSampleMAUI.Views.Widgets"
|
||||
xmlns:converters="clr-namespace:MvvmSampleMAUI.Converters"
|
||||
x:Class="MvvmSampleMAUI.Views.Widgets.SubredditWidget"
|
||||
x:TypeArguments="widgets:SubredditWidgetViewModel"
|
||||
x:DataType="widgets:SubredditWidgetViewModel">
|
||||
<ContentView.Resources>
|
||||
<converters:IsSelfPostToWidthRequestConverter WidthRequest="120"
|
||||
x:Key="IsSelfPostToWidthRequestConverter" />
|
||||
</ContentView.Resources>
|
||||
<!--Feed-->
|
||||
<Grid RowDefinitions="60, 8, *">
|
||||
|
||||
<!--Items list-->
|
||||
<CollectionView Grid.Row="2"
|
||||
ItemsSource="{Binding Posts}"
|
||||
SelectedItem="{Binding SelectedPost, Mode=TwoWay}"
|
||||
SelectionMode="Single"
|
||||
SelectionChanged="CollectionView_SelectionChanged"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay, Converter={StaticResource InvertedBoolConverter}}">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Post">
|
||||
<Border BorderColor="Black">
|
||||
<Grid ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Title}"
|
||||
FontSize="15"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Thumbnail}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
<!--Header with topic selector and refresh button-->
|
||||
<Border Padding="10,0,10,0">
|
||||
<Grid ColumnDefinitions="*, Auto">
|
||||
<Picker ItemsSource="{Binding Subreddits, Mode=OneWay}"
|
||||
SelectedItem="{Binding SelectedSubreddit, Mode=TwoWay}"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
Title="Subreddit">
|
||||
<Picker.Behaviors>
|
||||
<toolkit:EventToCommandBehavior EventName="SelectedIndexChanged"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Picker.Behaviors>
|
||||
</Picker>
|
||||
<Button Text="Refresh"
|
||||
Grid.Column="1"
|
||||
Command="{Binding LoadPostsCommand}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!--Loading bar-->
|
||||
<ActivityIndicator Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Margin="0, 10, 0, 0"
|
||||
VerticalOptions="Start"
|
||||
IsRunning="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</ContentView>
|
||||
<!--Items list-->
|
||||
<CollectionView Grid.Row="2"
|
||||
ItemsSource="{Binding Posts}"
|
||||
SelectedItem="{Binding SelectedPost, Mode=TwoWay}"
|
||||
SelectionMode="Single"
|
||||
SelectionChanged="CollectionView_SelectionChanged"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay, Converter={StaticResource InvertedBoolConverter}}">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Post">
|
||||
<Border Stroke="Black">
|
||||
<Grid ColumnSpacing="8"
|
||||
Padding="16"
|
||||
ColumnDefinitions="*, Auto">
|
||||
<Label Text="{Binding Title}"
|
||||
FontSize="15"
|
||||
LineBreakMode="WordWrap"
|
||||
VerticalOptions="Center" />
|
||||
<Image Grid.Column="1"
|
||||
Source="{Binding Thumbnail}"
|
||||
Aspect="AspectFit"
|
||||
HorizontalOptions="End"
|
||||
WidthRequest="{Binding Thumbnail, Converter={StaticResource IsSelfPostToWidthRequestConverter}}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
|
||||
<!--Loading bar-->
|
||||
<ActivityIndicator Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Margin="0, 10, 0, 0"
|
||||
VerticalOptions="Start"
|
||||
IsRunning="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}"
|
||||
IsVisible="{Binding LoadPostsCommand.IsRunning, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</mauiWidgets:BaseContentView>
|
|
@ -1,33 +1,40 @@
|
|||
using MvvmSample.Core.ViewModels.Widgets;
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
namespace MvvmSampleMAUI.Views.Widgets;
|
||||
|
||||
namespace MvvmSampleMAUI.Views.Widgets
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SubredditWidget : BaseContentView<SubredditWidgetViewModel>
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SubredditWidget : ContentView
|
||||
readonly WeakEventManager postSelectedEventManager = new();
|
||||
|
||||
public SubredditWidget(SubredditWidgetViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
public event EventHandler PostSelected;
|
||||
public SubredditWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = Ioc.Default.GetRequiredService<SubredditWidgetViewModel>();
|
||||
}
|
||||
|
||||
public SubredditWidgetViewModel ViewModel => (SubredditWidgetViewModel)BindingContext;
|
||||
|
||||
private void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
PostSelected?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void OnAppearing()
|
||||
{
|
||||
ViewModel.LoadPostsCommand.Execute(null);
|
||||
}
|
||||
Loaded += HandleLoaded;
|
||||
}
|
||||
|
||||
public event EventHandler PostSelected
|
||||
{
|
||||
add => postSelectedEventManager.AddEventHandler(value);
|
||||
remove => postSelectedEventManager.RemoveEventHandler(value);
|
||||
}
|
||||
|
||||
void CollectionView_SelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sender);
|
||||
|
||||
var collectionView = (CollectionView)sender;
|
||||
|
||||
OnPostSelected();
|
||||
|
||||
collectionView.SelectedItem = null;
|
||||
}
|
||||
|
||||
void HandleLoaded(object? sender, EventArgs e)
|
||||
{
|
||||
BindingContext.LoadPostsCommand.Execute(null);
|
||||
}
|
||||
|
||||
void OnPostSelected() => postSelectedEventManager.HandleEvent(this, EventArgs.Empty, nameof(PostSelected));
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
@ -14,7 +15,7 @@ namespace MvvmSampleXF.Droid
|
|||
{
|
||||
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "13.2.2.120")]
|
||||
public partial class Resource
|
||||
{
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче