Skip to content

Commit 05d643b

Browse files
author
Paul Betts
committed
Merge pull request #503 from reactiveui/activation
View / ViewModel Activation
2 parents 1f845be + 1e48ff0 commit 05d643b

39 files changed

+842
-136
lines changed

MobileSample-WinRT/App.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public App()
3232
protected override void OnLaunched(LaunchActivatedEventArgs args)
3333
{
3434
Locator.CurrentMutable.Register(() => new AppBootstrapper(), typeof(IApplicationRootState));
35-
3635
base.OnLaunched(args);
36+
37+
RxApp.MainThreadScheduler.GetType();
3738
var host = Locator.Current.GetService<ISuspensionHost>();
3839
host.SetupDefaultSuspendResume();
3940
}

MobileSample-WinRT/MobileSample-WinRT.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<TargetFrameworkVersion />
2121
</PropertyGroup>
2222
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23-
<PlatformTarget>AnyCPU</PlatformTarget>
23+
<PlatformTarget>x86</PlatformTarget>
2424
<DebugSymbols>true</DebugSymbols>
2525
<DebugType>full</DebugType>
2626
<Optimize>false</Optimize>
@@ -59,6 +59,9 @@
5959
<Compile Include="ViewModels\TestPage2ViewModel.cs" />
6060
<Compile Include="ViewModels\TestPage3ViewModel.cs" />
6161
<Compile Include="ViewModels\TestPage1ViewModel.cs" />
62+
<Compile Include="Views\StringTileView.xaml.cs">
63+
<DependentUpon>StringTileView.xaml</DependentUpon>
64+
</Compile>
6265
<Compile Include="Views\TestPage3View.xaml.cs">
6366
<DependentUpon>TestPage3View.xaml</DependentUpon>
6467
</Compile>
@@ -99,6 +102,10 @@
99102
<SubType>Designer</SubType>
100103
<Generator>MSBuild:Compile</Generator>
101104
</Page>
105+
<Page Include="Views\StringTileView.xaml">
106+
<SubType>Designer</SubType>
107+
<Generator>MSBuild:Compile</Generator>
108+
</Page>
102109
<Page Include="Views\TestPage3View.xaml">
103110
<Generator>MSBuild:Compile</Generator>
104111
<SubType>Designer</SubType>
@@ -167,4 +174,4 @@
167174
<Target Name="AfterBuild">
168175
</Target>
169176
-->
170-
</Project>
177+
</Project>

MobileSample-WinRT/ViewModels/AppBootstrapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public AppBootstrapper()
3333
resolver.Register(() => new TestPage1View(), typeof(IViewFor<TestPage1ViewModel>), "FullScreenLandscape");
3434
resolver.Register(() => new TestPage2View(), typeof(IViewFor<TestPage2ViewModel>), "FullScreenLandscape");
3535
resolver.Register(() => new TestPage3View(), typeof(IViewFor<TestPage3ViewModel>), "FullScreenLandscape");
36+
resolver.Register(() => new StringTileView(), typeof(IViewFor<StringTileViewModel>));
3637

3738
resolver.Register(() => new TestPage1ViewModel(), typeof(TestPage1ViewModel));
3839
resolver.Register(() => new TestPage2ViewModel(), typeof(TestPage2ViewModel));

MobileSample-WinRT/ViewModels/TestPage3ViewModel.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
using System;
2+
using System.Linq;
23
using System.Runtime.Serialization;
34
using ReactiveUI;
45
using Splat;
56

67
namespace MobileSample_WinRT.ViewModels
78
{
9+
public class StringTileViewModel : ReactiveObject
10+
{
11+
public string Model { get; protected set; }
12+
13+
public StringTileViewModel(string someString)
14+
{
15+
Model = someString;
16+
}
17+
}
18+
819
[DataContract]
920
public class TestPage3ViewModel : ReactiveObject, IRoutableViewModel
1021
{
@@ -18,10 +29,28 @@ public Guid RandomGuid {
1829
set { this.RaiseAndSetIfChanged(ref _RandomGuid, value); }
1930
}
2031

32+
public ReactiveList<string> ListOfStrings { get; protected set; }
33+
public IReactiveDerivedList<StringTileViewModel> ListOfTiles { get; protected set; }
34+
35+
public ReactiveCommand PopulateList { get; protected set; }
36+
public ReactiveCommand ClearList { get; protected set; }
37+
2138
public TestPage3ViewModel(IScreen screen = null)
2239
{
2340
HostScreen = screen ?? Locator.Current.GetService<IScreen>();
2441
RandomGuid = Guid.NewGuid();
42+
43+
ListOfStrings = new ReactiveList<string>();
44+
ListOfTiles = ListOfStrings.CreateDerivedCollection(x => new StringTileViewModel(x));
45+
46+
PopulateList = new ReactiveCommand();
47+
PopulateList.Subscribe(_ => ListOfStrings.AddRange(Enumerable.Range(0, 50).Select(__ => Guid.NewGuid().ToString())));
48+
49+
ClearList = new ReactiveCommand();
50+
ClearList.Subscribe(_ => {
51+
ListOfStrings.Clear();
52+
GC.Collect(10, GCCollectionMode.Forced, true);
53+
});
2554
}
2655
}
2756
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<UserControl
2+
x:Class="MobileSample_WinRT.Views.StringTileView"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:MobileSample_WinRT.Views"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
Width="400"
10+
Height="64"
11+
d:DesignHeight="300"
12+
d:DesignWidth="400">
13+
14+
<Grid>
15+
<TextBlock x:Name="Model" FontSize="32" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Text="Hello" />
16+
</Grid>
17+
</UserControl>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using MobileSample_WinRT.ViewModels;
7+
using ReactiveUI;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
19+
20+
namespace MobileSample_WinRT.Views
21+
{
22+
public sealed partial class StringTileView : UserControl, IViewFor<StringTileViewModel>
23+
{
24+
public StringTileView()
25+
{
26+
this.InitializeComponent();
27+
28+
this.WhenActivated(d => {
29+
d(this.OneWayBind(ViewModel, x => x.Model, x => x.Model.Text));
30+
});
31+
}
32+
33+
public StringTileViewModel ViewModel {
34+
get { return (StringTileViewModel)GetValue(ViewModelProperty); }
35+
set { SetValue(ViewModelProperty, value); }
36+
}
37+
public static readonly DependencyProperty ViewModelProperty =
38+
DependencyProperty.Register("ViewModel", typeof(StringTileViewModel), typeof(StringTileView), new PropertyMetadata(null));
39+
40+
object IViewFor.ViewModel {
41+
get { return ViewModel; }
42+
set { ViewModel = (StringTileViewModel)value; }
43+
}
44+
}
45+
}

MobileSample-WinRT/Views/TestPage3View.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
xmlns:local="using:MobileSample_WinRT.Views"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:xaml="using:ReactiveUI.Xaml"
89
mc:Ignorable="d">
910

1011
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
1112
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
1213
<TextBlock Style="{StaticResource HeaderTextStyle}" Text="Page 3." HorizontalAlignment="Center"/>
1314
<TextBlock x:Name="RandomGuid" Style="{StaticResource BodyTextStyle}" Margin="0,16,0,0" FontSize="24" HorizontalAlignment="Center"/>
15+
<ListView x:Name="ListOfTiles" Width="400" Height="550">
16+
<ListView.ItemTemplate>
17+
<DataTemplate>
18+
<xaml:ViewModelViewHost ViewModel="{Binding}" />
19+
</DataTemplate>
20+
</ListView.ItemTemplate>
21+
</ListView>
22+
<StackPanel Orientation="Horizontal">
23+
<Button x:Name="PopulateList" Content="Populate List" />
24+
<Button x:Name="ClearList" Content="Clear List" />
25+
</StackPanel>
1426
</StackPanel>
1527
</Grid>
1628
</Page>

MobileSample-WinRT/Views/TestPage3View.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ public sealed partial class TestPage3View : Page, IViewFor<TestPage3ViewModel>
2323
public TestPage3View()
2424
{
2525
this.InitializeComponent();
26-
this.OneWayBind(ViewModel, x => x.RandomGuid, x => x.RandomGuid.Text);
26+
27+
this.WhenActivated(d => {
28+
d(this.OneWayBind(ViewModel, x => x.RandomGuid, x => x.RandomGuid.Text));
29+
d(this.OneWayBind(ViewModel, x => x.ListOfTiles, x => x.ListOfTiles.ItemsSource));
30+
31+
d(this.BindCommand(ViewModel, x => x.PopulateList, x => x.PopulateList));
32+
d(this.BindCommand(ViewModel, x => x.ClearList, x => x.ClearList));
33+
});
2734
}
2835

2936
public TestPage3ViewModel ViewModel {

ReactiveUI.Events/ReactiveUI.Events_Monomac.csproj

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@
130130
<Reference Include="Microsoft.CSharp" />
131131
<Reference Include="System.ComponentModel.DataAnnotations" />
132132
<Reference Include="System.Drawing" />
133-
<Reference Include="XamMac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065">
134-
<Private>False</Private>
135-
</Reference>
133+
<Reference Include="XamMac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065" />
136134
<Reference Include="System.Reactive.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
137135
<HintPath>..\ext\mono\System.Reactive.Core.dll</HintPath>
138136
</Reference>
@@ -145,21 +143,11 @@
145143
<Reference Include="System.Reactive.PlatformServices, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
146144
<HintPath>..\ext\mono\System.Reactive.PlatformServices.dll</HintPath>
147145
</Reference>
148-
<Reference Include="System.Reactive.Core, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
149-
<Private>False</Private>
150-
</Reference>
151-
<Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
152-
<Private>False</Private>
153-
</Reference>
154-
<Reference Include="System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
155-
<Private>False</Private>
156-
</Reference>
157-
<Reference Include="System.Reactive.PlatformServices, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
158-
<Private>False</Private>
159-
</Reference>
160-
<Reference Include="System.Reactive.Debugger, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
161-
<Private>False</Private>
162-
</Reference>
146+
<Reference Include="System.Reactive.Core, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
147+
<Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
148+
<Reference Include="System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
149+
<Reference Include="System.Reactive.PlatformServices, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
150+
<Reference Include="System.Reactive.Debugger, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
163151
<Reference Include="XamMac" />
164152
</ItemGroup>
165153
<ItemGroup>

ReactiveUI.Mobile/ReactiveUI.Mobile_Monodroid.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@
6666
<RunCodeAnalysis>false</RunCodeAnalysis>
6767
<CodeContractsPointerObligations>False</CodeContractsPointerObligations>
6868
<AndroidLinkMode>None</AndroidLinkMode>
69-
<DocumentationFile>
70-
</DocumentationFile>
7169
</PropertyGroup>
7270
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
7371
<DebugType>pdbonly</DebugType>

0 commit comments

Comments
 (0)