Skip to content

Commit 1725fe4

Browse files
authored
housekeeping: Use ReactiveWindow in the Getting Started app (#1830)
1 parent b7db59f commit 1725fe4

File tree

4 files changed

+35
-51
lines changed

4 files changed

+35
-51
lines changed

samples/getting-started/ReactiveDemo/AppViewModel.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Threading.Tasks;
3+
using System.Linq;
44
using System.Reactive.Linq;
55
using System.Threading;
6-
using System.Linq;
7-
using ReactiveUI;
8-
using NuGet.Protocol.Core.Types;
9-
using NuGet.Protocol;
6+
using System.Threading.Tasks;
107
using NuGet.Configuration;
8+
using NuGet.Protocol;
9+
using NuGet.Protocol.Core.Types;
10+
using ReactiveUI;
1111

1212
namespace ReactiveDemo
1313
{
@@ -108,13 +108,13 @@ private async Task<IEnumerable<NugetDetailsViewModel>> SearchNuGetPackages(
108108
{
109109
var providers = new List<Lazy<INuGetResourceProvider>>();
110110
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
111-
var packageSource = new PackageSource("https://api.nuget.org/v3/index.json");
112-
var sourceRepository = new SourceRepository(packageSource, providers);
111+
var package = new PackageSource("https://api.nuget.org/v3/index.json");
112+
var source = new SourceRepository(package, providers);
113113

114114
var filter = new SearchFilter(false);
115-
var searchResource = await sourceRepository.GetResourceAsync<PackageSearchResource>();
116-
var searchMetadata = await searchResource.SearchAsync(term, filter, 0, 10, null, token);
117-
return searchMetadata.Select(x => new NugetDetailsViewModel(x));
115+
var resource = await source.GetResourceAsync<PackageSearchResource>().ConfigureAwait(false);
116+
var metadata = await resource.SearchAsync(term, filter, 0, 10, null, token).ConfigureAwait(false);
117+
return metadata.Select(x => new NugetDetailsViewModel(x));
118118
}
119119
}
120120
}

samples/getting-started/ReactiveDemo/MainWindow.xaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
<Window x:Class="ReactiveDemo.MainWindow"
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
Title="NuGet Browser"
7-
mc:Ignorable="d" Height="450" Width="800">
1+
<reactiveui:ReactiveWindow
2+
x:Class="ReactiveDemo.MainWindow"
3+
x:TypeArguments="reactivedemo:AppViewModel"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:reactivedemo="clr-namespace:ReactiveDemo"
9+
xmlns:reactiveui="http://reactiveui.net"
10+
Title="NuGet Browser" Height="450" Width="800"
11+
mc:Ignorable="d">
812
<Grid Margin="12">
913
<Grid.ColumnDefinitions>
1014
<ColumnDefinition Width="Auto" />
@@ -21,4 +25,4 @@
2125
Grid.Row="1" Margin="0,6,0,0" HorizontalContentAlignment="Stretch"
2226
ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
2327
</Grid>
24-
</Window>
28+
</reactiveui:ReactiveWindow>
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
using System.Reactive.Disposables;
2-
using System.Windows;
32
using ReactiveUI;
43

54
namespace ReactiveDemo
65
{
7-
public partial class MainWindow : IViewFor<AppViewModel>
6+
// MainWindow class derives off ReactiveWindow which implements the IViewFor<TViewModel>
7+
// interface using a WPF DependencyProperty. We need this to use WhenActivated extension
8+
// method that helps us handling View and ViewModel activation and deactivation.
9+
public partial class MainWindow : ReactiveWindow<AppViewModel>
810
{
9-
// Using a DependencyProperty as the backing store for ViewModel.
10-
// This enables animation, styling, binding, etc.
11-
public static readonly DependencyProperty ViewModelProperty =
12-
DependencyProperty.Register("ViewModel",
13-
typeof(AppViewModel), typeof(MainWindow),
14-
new PropertyMetadata(null));
15-
1611
public MainWindow()
1712
{
1813
InitializeComponent();
1914
ViewModel = new AppViewModel();
2015

21-
// We create our bindings here. These are the code behind bindings which allow
16+
// We create our bindings here. These are the code behind bindings which allow
2217
// type safety. The bindings will only become active when the Window is being shown.
23-
// We register our subscription in our disposableRegistration, this will cause
18+
// We register our subscription in our disposableRegistration, this will cause
2419
// the binding subscription to become inactive when the Window is closed.
25-
// The disposableRegistration is a CompositeDisposable which is a container of
26-
// other Disposables. We use the DisposeWith() extension method which simply adds
20+
// The disposableRegistration is a CompositeDisposable which is a container of
21+
// other Disposables. We use the DisposeWith() extension method which simply adds
2722
// the subscription disposable to the CompositeDisposable.
2823
this.WhenActivated(disposableRegistration =>
2924
{
@@ -45,21 +40,5 @@ public MainWindow()
4540
.DisposeWith(disposableRegistration);
4641
});
4742
}
48-
49-
// Our main view model instance.
50-
public AppViewModel ViewModel
51-
{
52-
get => (AppViewModel)GetValue(ViewModelProperty);
53-
set => SetValue(ViewModelProperty, value);
54-
}
55-
56-
// This is required by the interface IViewFor, you always just set it to use the
57-
// main ViewModel property. Note on XAML based platforms we have a control called
58-
// ReactiveUserControl that abstracts this.
59-
object IViewFor.ViewModel
60-
{
61-
get => ViewModel;
62-
set => ViewModel = (AppViewModel)value;
63-
}
6443
}
6544
}

samples/getting-started/ReactiveDemo/ReactiveDemo.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<WarningLevel>4</WarningLevel>
1515
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1616
<Deterministic>true</Deterministic>
17+
<CodeAnalysisRuleSet>..\..\src\reactiveui.tests.ruleset</CodeAnalysisRuleSet>
1718
</PropertyGroup>
1819
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1920
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -70,9 +71,9 @@
7071
<None Include="App.config" />
7172
</ItemGroup>
7273
<ItemGroup>
73-
<PackageReference Include="NuGet.Client" Version="4.2.0"/>
74-
<PackageReference Include="NuGet.Protocol.Core.v3" Version="4.2.0"/>
75-
<PackageReference Include="ReactiveUI.WPF" Version="8.7.2"/>
74+
<PackageReference Include="NuGet.Client" Version="4.2.0" />
75+
<PackageReference Include="NuGet.Protocol.Core.v3" Version="4.2.0" />
76+
<PackageReference Include="ReactiveUI.WPF" Version="*" />
7677
</ItemGroup>
7778
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
78-
</Project>
79+
</Project>

0 commit comments

Comments
 (0)