committed by
GitHub
18 changed files with 271 additions and 4 deletions
@ -0,0 +1,5 @@ |
|||||
|
<ProjectConfiguration> |
||||
|
<Settings> |
||||
|
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
||||
|
</Settings> |
||||
|
</ProjectConfiguration> |
||||
@ -0,0 +1,8 @@ |
|||||
|
<Application |
||||
|
xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
x:Class="ReactiveUIDemo.App"> |
||||
|
<Application.Styles> |
||||
|
<FluentTheme /> |
||||
|
</Application.Styles> |
||||
|
</Application> |
||||
@ -0,0 +1,37 @@ |
|||||
|
using Avalonia; |
||||
|
using Avalonia.Controls.ApplicationLifetimes; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using Avalonia.ReactiveUI; |
||||
|
using ReactiveUI; |
||||
|
using ReactiveUIDemo.ViewModels; |
||||
|
using ReactiveUIDemo.Views; |
||||
|
using Splat; |
||||
|
|
||||
|
namespace ReactiveUIDemo |
||||
|
{ |
||||
|
public class App : Application |
||||
|
{ |
||||
|
public override void Initialize() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
Locator.CurrentMutable.Register(() => new FooView(), typeof(IViewFor<FooViewModel>)); |
||||
|
Locator.CurrentMutable.Register(() => new BarView(), typeof(IViewFor<BarViewModel>)); |
||||
|
} |
||||
|
|
||||
|
public override void OnFrameworkInitializationCompleted() |
||||
|
{ |
||||
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) |
||||
|
desktop.MainWindow = new MainWindow(); |
||||
|
base.OnFrameworkInitializationCompleted(); |
||||
|
} |
||||
|
|
||||
|
public static int Main(string[] args) |
||||
|
=> BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); |
||||
|
|
||||
|
public static AppBuilder BuildAvaloniaApp() |
||||
|
=> AppBuilder.Configure<App>() |
||||
|
.UsePlatformDetect() |
||||
|
.UseReactiveUI() |
||||
|
.LogToTrace(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
<Window xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' |
||||
|
x:Class="ReactiveUIDemo.MainWindow" |
||||
|
xmlns:vm="using:ReactiveUIDemo.ViewModels" |
||||
|
xmlns:rxui="using:Avalonia.ReactiveUI" |
||||
|
Title="AvaloniaUI ReactiveUI Demo" |
||||
|
x:DataType="vm:MainWindowViewModel"> |
||||
|
<TabControl TabStripPlacement="Left"> |
||||
|
<TabItem Header="RoutedViewHost"> |
||||
|
<DockPanel DataContext="{Binding RoutedViewHost}"> |
||||
|
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Spacing="8"> |
||||
|
<Button Command="{Binding ShowFoo}">Foo</Button> |
||||
|
<Button Command="{Binding ShowBar}">Bar</Button> |
||||
|
</StackPanel> |
||||
|
<rxui:RoutedViewHost Router="{Binding Router}"/> |
||||
|
</DockPanel> |
||||
|
</TabItem> |
||||
|
</TabControl> |
||||
|
</Window> |
||||
@ -0,0 +1,22 @@ |
|||||
|
using ReactiveUIDemo.ViewModels; |
||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
|
||||
|
namespace ReactiveUIDemo |
||||
|
{ |
||||
|
public class MainWindow : Window |
||||
|
{ |
||||
|
public MainWindow() |
||||
|
{ |
||||
|
this.InitializeComponent(); |
||||
|
this.DataContext = new MainWindowViewModel(); |
||||
|
this.AttachDevTools(); |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
<PropertyGroup> |
||||
|
<OutputType>Exe</OutputType> |
||||
|
<TargetFramework>net6.0</TargetFramework> |
||||
|
<Nullable>enable</Nullable> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<Compile Update="Views\BarView.axaml.cs"> |
||||
|
<DependentUpon>BarView.axaml</DependentUpon> |
||||
|
</Compile> |
||||
|
<Compile Update="Views\FooView.axaml.cs"> |
||||
|
<DependentUpon>FooView.axaml</DependentUpon> |
||||
|
</Compile> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<Import Project="..\..\build\SampleApp.props" /> |
||||
|
<Import Project="..\..\build\ReferenceCoreLibraries.props" /> |
||||
|
<Import Project="..\..\build\BuildTargets.targets" /> |
||||
|
<Import Project="..\..\build\Rx.props" /> |
||||
|
<Import Project="..\..\build\ReactiveUI.props" /> |
||||
|
</Project> |
||||
@ -0,0 +1,11 @@ |
|||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ReactiveUIDemo.ViewModels |
||||
|
{ |
||||
|
internal class BarViewModel : ReactiveObject, IRoutableViewModel |
||||
|
{ |
||||
|
public BarViewModel(IScreen screen) => HostScreen = screen; |
||||
|
public string UrlPathSegment => "Bar"; |
||||
|
public IScreen HostScreen { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ReactiveUIDemo.ViewModels |
||||
|
{ |
||||
|
internal class FooViewModel : ReactiveObject, IRoutableViewModel |
||||
|
{ |
||||
|
public FooViewModel(IScreen screen) => HostScreen = screen; |
||||
|
public string UrlPathSegment => "Foo"; |
||||
|
public IScreen HostScreen { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ReactiveUIDemo.ViewModels |
||||
|
{ |
||||
|
internal class MainWindowViewModel : ReactiveObject |
||||
|
{ |
||||
|
public RoutedViewHostPageViewModel RoutedViewHost { get; } = new(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ReactiveUIDemo.ViewModels |
||||
|
{ |
||||
|
internal class RoutedViewHostPageViewModel : ReactiveObject, IScreen |
||||
|
{ |
||||
|
public RoutedViewHostPageViewModel() |
||||
|
{ |
||||
|
Foo = new(this); |
||||
|
Bar = new(this); |
||||
|
Router.Navigate.Execute(Foo); |
||||
|
} |
||||
|
|
||||
|
public RoutingState Router { get; } = new(); |
||||
|
public FooViewModel Foo { get; } |
||||
|
public BarViewModel Bar { get; } |
||||
|
|
||||
|
public void ShowFoo() => Router.Navigate.Execute(Foo); |
||||
|
public void ShowBar() => Router.Navigate.Execute(Bar); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
|
x:Class="ReactiveUIDemo.Views.BarView" |
||||
|
HorizontalAlignment="Stretch" |
||||
|
VerticalAlignment="Stretch"> |
||||
|
<Border Background="Blue"> |
||||
|
<TextBlock HorizontalAlignment="Center" |
||||
|
VerticalAlignment="Center" |
||||
|
FontSize="48"> |
||||
|
Bar! |
||||
|
</TextBlock> |
||||
|
</Border> |
||||
|
</UserControl> |
||||
@ -0,0 +1,28 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using ReactiveUI; |
||||
|
using ReactiveUIDemo.ViewModels; |
||||
|
|
||||
|
namespace ReactiveUIDemo.Views |
||||
|
{ |
||||
|
internal partial class BarView : UserControl, IViewFor<BarViewModel> |
||||
|
{ |
||||
|
public BarView() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
} |
||||
|
|
||||
|
public BarViewModel? ViewModel { get; set; } |
||||
|
|
||||
|
object? IViewFor.ViewModel |
||||
|
{ |
||||
|
get => ViewModel; |
||||
|
set => ViewModel = (BarViewModel?)value; |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
|
x:Class="ReactiveUIDemo.Views.FooView" |
||||
|
HorizontalAlignment="Stretch" |
||||
|
VerticalAlignment="Stretch"> |
||||
|
<Border Background="Red"> |
||||
|
<TextBlock HorizontalAlignment="Center" |
||||
|
VerticalAlignment="Center" |
||||
|
FontSize="48"> |
||||
|
Foo! |
||||
|
</TextBlock> |
||||
|
</Border> |
||||
|
</UserControl> |
||||
@ -0,0 +1,28 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using ReactiveUI; |
||||
|
using ReactiveUIDemo.ViewModels; |
||||
|
|
||||
|
namespace ReactiveUIDemo.Views |
||||
|
{ |
||||
|
internal partial class FooView : UserControl, IViewFor<FooViewModel> |
||||
|
{ |
||||
|
public FooView() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
} |
||||
|
|
||||
|
public FooViewModel? ViewModel { get; set; } |
||||
|
|
||||
|
object? IViewFor.ViewModel |
||||
|
{ |
||||
|
get => ViewModel; |
||||
|
set => ViewModel = (FooViewModel?)value; |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue