├── .gitattributes ├── .gitignore ├── README.md ├── snippets ├── r# │ └── rxui.DotSettings └── vs │ ├── iv4prop.snippet │ ├── rasprop.snippet │ └── roprop.snippet └── src ├── complete ├── ex1-readonlyproperties │ ├── Ex1.Tests │ │ ├── Ex1.Tests.csproj │ │ ├── PersonViewModelTests.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ ├── Ex1 │ │ ├── Ex1.csproj │ │ ├── PersonViewModel.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ └── ex1-readonlyproperties.sln ├── ex2-reactivecommand-part1 │ ├── Ex2.Tests │ │ ├── Ex2.Tests.csproj │ │ ├── PersonViewModelTests.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ ├── Ex2 │ │ ├── Ex2.csproj │ │ ├── PersonViewModel.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ └── ex2-reactivecommand-part1.sln ├── ex3-reactivecommand-part2 │ ├── Ex3.Tests │ │ ├── Ex3.Tests.csproj │ │ ├── PersonViewModelTests.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ ├── Ex3 │ │ ├── Ex3.csproj │ │ ├── PersonViewModel.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ └── ex3-reactivecommand-part2.sln ├── ex4-bindings-part1 │ ├── Ex4 │ │ ├── App.config │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── Ex4.csproj │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── MainWindowModel.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ └── packages.config │ └── ex4-bindings-part1.sln ├── ex5-viewmodel-composition │ ├── Ex5 │ │ ├── App.config │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── AppBootstrapper.cs │ │ ├── ControlStyles.ReactiveUI.xaml │ │ ├── Ex5.csproj │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── MainWindowModel.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ ├── TitleBarView.xaml │ │ ├── TitleBarView.xaml.cs │ │ ├── TitleBarViewModel.cs │ │ └── packages.config │ └── ex5-viewmodel-composition.sln ├── ex6-bindings-part2 │ ├── Ex6 │ │ ├── App.config │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── AppBootstrapper.cs │ │ ├── ControlStyles.ReactiveUI.xaml │ │ ├── Ex6.csproj │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── MainWindowModel.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ └── packages.config │ └── ex6-bindings-part2.sln ├── ex7-bindings-part3 │ ├── Ex7 │ │ ├── App.config │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── AppBootstrapper.cs │ │ ├── ControlStyles.ReactiveUI.xaml │ │ ├── Ex7.csproj │ │ ├── FakeData.cs │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── MainWindowModel.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ ├── TweetView.xaml │ │ ├── TweetView.xaml.cs │ │ ├── TweetViewModel.cs │ │ └── packages.config │ └── ex7-bindings-part3.sln ├── ex8-routing │ ├── Ex8 │ │ ├── App.config │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── AppBootstrapper.cs │ │ ├── Ex8.csproj │ │ ├── MainWindowView.xaml │ │ ├── MainWindowView.xaml.cs │ │ ├── MainWindowViewModel.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ ├── ViewA.xaml │ │ ├── ViewA.xaml.cs │ │ ├── ViewB.xaml │ │ ├── ViewB.xaml.cs │ │ ├── ViewInstanceCount.cs │ │ ├── ViewModelA.cs │ │ ├── ViewModelB.cs │ │ ├── ViewModelInstanceCount.cs │ │ └── packages.config │ └── ex8-routing.sln └── ex9-derivedlists │ ├── Ex9 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── Ex9.csproj │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── MainWindowModel.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── TestDataSource.cs │ ├── TestModel.cs │ ├── TestView.xaml │ ├── TestView.xaml.cs │ ├── TestViewModel.cs │ └── packages.config │ └── ex9-derivedlists.sln └── exercises ├── ex1-readonlyproperties ├── Ex1.Tests │ ├── Ex1.Tests.csproj │ ├── PersonViewModelTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── Ex1 │ ├── Ex1.csproj │ ├── PersonViewModel.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── ex1-readonlyproperties.sln ├── ex2-reactivecommand-part1 ├── Ex2.Tests │ ├── Ex2.Tests.csproj │ ├── PersonViewModelTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── Ex2 │ ├── Ex2.csproj │ ├── PersonViewModel.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── ex2-reactivecommand-part1.sln ├── ex3-reactivecommand-part2 ├── Ex3.Tests │ ├── Ex3.Tests.csproj │ ├── PersonViewModelTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── Ex3 │ ├── Ex3.csproj │ ├── PersonViewModel.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── ex3-reactivecommand-part2.sln ├── ex4-bindings-part1 ├── Ex4 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── Ex4.csproj │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── MainWindowModel.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── packages.config └── ex4-bindings-part1.sln ├── ex5-viewmodel-composition ├── Ex5 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── AppBootstrapper.cs │ ├── ControlStyles.ReactiveUI.xaml │ ├── Ex5.csproj │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── MainWindowModel.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── TitleBarView.xaml │ ├── TitleBarView.xaml.cs │ ├── TitleBarViewModel.cs │ └── packages.config └── ex5-viewmodel-composition.sln ├── ex6-bindings-part2 ├── Ex6 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── AppBootstrapper.cs │ ├── ControlStyles.ReactiveUI.xaml │ ├── Ex6.csproj │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── MainWindowModel.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── packages.config └── ex6-bindings-part2.sln ├── ex7-bindings-part3 ├── Ex7 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── AppBootstrapper.cs │ ├── ControlStyles.ReactiveUI.xaml │ ├── Ex7.csproj │ ├── FakeData.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── MainWindowModel.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── TweetView.xaml │ ├── TweetView.xaml.cs │ ├── TweetViewModel.cs │ └── packages.config └── ex7-bindings-part3.sln ├── ex8-routing ├── Ex8 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── AppBootstrapper.cs │ ├── Ex8.csproj │ ├── MainWindowView.xaml │ ├── MainWindowView.xaml.cs │ ├── MainWindowViewModel.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── ViewA.xaml │ ├── ViewA.xaml.cs │ ├── ViewB.xaml │ ├── ViewB.xaml.cs │ ├── ViewInstanceCount.cs │ ├── ViewModelA.cs │ ├── ViewModelB.cs │ ├── ViewModelInstanceCount.cs │ └── packages.config └── ex8-routing.sln └── ex9-derivedlists ├── Ex9 ├── App.config ├── App.xaml ├── App.xaml.cs ├── Ex9.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── MainWindowModel.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── TestDataSource.cs ├── TestModel.cs ├── TestView.xaml ├── TestView.xaml.cs ├── TestViewModel.cs └── packages.config └── ex9-derivedlists.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /snippets/vs/iv4prop.snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | IViewForProp 6 | iv4prop 7 | Generates the dependency prop for IViewFor 8 | 9 | Expansion 10 | 11 |
12 | 13 | 14 | 15 | classname 16 | View type 17 | ClassName() 18 | ClassNamePlaceholder 19 | 20 | 21 | 22 | 40 | 41 | 42 |
43 |
-------------------------------------------------------------------------------- /snippets/vs/rasprop.snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | RaiseAndSetProp 6 | rasprop 7 | Generates ReactiveUI RaiseAndSetIfChanged property 8 | 9 | Expansion 10 | 11 |
12 | 13 | 14 | 15 | type 16 | Property type 17 | string 18 | 19 | 20 | propName 21 | MyNotProp 22 | The property name 23 | 24 | 25 | 26 | 32 | 33 | 34 |
35 |
-------------------------------------------------------------------------------- /snippets/vs/roprop.snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | RaiseAndSetProp 6 | roprop 7 | Generates ReactiveUI read-only property 8 | 9 | Expansion 10 | 11 |
12 | 13 | 14 | 15 | type 16 | Property type 17 | string 18 | 19 | 20 | propName 21 | MyNotProp 22 | The property name 23 | 24 | 25 | 26 | _$propName$; 27 | public $type$ $propName$ 28 | { 29 | get { return _$propName$.Value; } 30 | }$end$]]> 31 | 32 | 33 |
34 |
-------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/Ex1.Tests/PersonViewModelTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Ex1.Tests 4 | { 5 | [TestFixture] 6 | public class PersonViewModelTests 7 | { 8 | [Test] 9 | public void FullNameIsMadeUpFromFirstNameAndLastName() 10 | { 11 | var sut = new PersonViewModel {FirstName = "Jane", LastName = "Appleseed"}; 12 | 13 | Assert.AreEqual("Jane Appleseed", sut.FullName); 14 | } 15 | 16 | [Test] 17 | public void FullNameUpdatesWhenFirstNameChanges() 18 | { 19 | var sut = new PersonViewModel {FirstName = "Jane", LastName = "Appleseed"}; 20 | sut.FirstName = "Joe"; 21 | 22 | Assert.AreEqual("Joe Appleseed", sut.FullName); 23 | } 24 | 25 | [Test] 26 | public void FullNameUpdatesWhenLastNameChanges() 27 | { 28 | var sut = new PersonViewModel {FirstName = "Jane", LastName = "Appleseed"}; 29 | sut.LastName = "Smith"; 30 | 31 | Assert.AreEqual("Jane Smith", sut.FullName); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/Ex1.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Ex1.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vagrant Inc.")] 12 | [assembly: AssemblyProduct("Ex1.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Vagrant Inc. 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f652787a-af8e-4b17-b662-eeeefa6ff48c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/Ex1.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/Ex1/PersonViewModel.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | 3 | namespace Ex1 4 | { 5 | public class PersonViewModel : ReactiveObject 6 | { 7 | public PersonViewModel() 8 | { 9 | _fullName = this.WhenAnyValue(vm => vm.FirstName, vm => vm.LastName, (f, l) => string.Format("{0} {1}", f, l)) 10 | .ToProperty(this, vm => vm.FullName); 11 | } 12 | 13 | private readonly ObservableAsPropertyHelper _fullName; 14 | public string FullName 15 | { 16 | get { return _fullName.Value; } 17 | } 18 | 19 | private string _firstName; 20 | public string FirstName 21 | { 22 | get { return _firstName; } 23 | set { this.RaiseAndSetIfChanged(ref _firstName, value); } 24 | } 25 | 26 | private string _lastName; 27 | public string LastName 28 | { 29 | get { return _lastName; } 30 | set { this.RaiseAndSetIfChanged(ref _lastName, value); } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/Ex1/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Ex1")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vagrant Inc.")] 12 | [assembly: AssemblyProduct("Ex1")] 13 | [assembly: AssemblyCopyright("Copyright © Vagrant Inc. 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("3cfe10f3-975a-4e5c-85e2-6ee359a4897e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/Ex1/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex1-readonlyproperties/ex1-readonlyproperties.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex1.Tests", "Ex1.Tests\Ex1.Tests.csproj", "{9A729109-8D64-4AA6-8331-B238AAC0E3C7}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex1", "Ex1\Ex1.csproj", "{403F8DE4-409C-4259-BF3D-A1E20AD30739}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9A729109-8D64-4AA6-8331-B238AAC0E3C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9A729109-8D64-4AA6-8331-B238AAC0E3C7}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9A729109-8D64-4AA6-8331-B238AAC0E3C7}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {9A729109-8D64-4AA6-8331-B238AAC0E3C7}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {403F8DE4-409C-4259-BF3D-A1E20AD30739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {403F8DE4-409C-4259-BF3D-A1E20AD30739}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {403F8DE4-409C-4259-BF3D-A1E20AD30739}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {403F8DE4-409C-4259-BF3D-A1E20AD30739}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/Ex2.Tests/PersonViewModelTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Ex2.Tests 4 | { 5 | [TestFixture] 6 | public class PersonViewModelTests 7 | { 8 | [Test] 9 | public void ChangeNameCanOnlyBeExecutedIfFirstNameAndLastNameAreFilled() 10 | { 11 | var sut = new PersonViewModel(); 12 | 13 | Assert.IsFalse(sut.ChangeName.CanExecute(null)); 14 | 15 | sut.FirstName = "Jane"; 16 | 17 | Assert.IsFalse(sut.ChangeName.CanExecute(null)); 18 | 19 | sut.LastName = "Appleseed"; 20 | 21 | Assert.IsTrue(sut.ChangeName.CanExecute(null)); 22 | } 23 | 24 | [Test] 25 | public void FullNameIsMadeUpFromFirstNameAndLastName() 26 | { 27 | var sut = new PersonViewModel { FirstName = "Jane", LastName = "Appleseed" }; 28 | 29 | Assert.AreEqual("Jane Appleseed", sut.FullName); 30 | } 31 | 32 | [Test] 33 | public void FullNameUpdatesWhenFirstNameChanges() 34 | { 35 | var sut = new PersonViewModel { FirstName = "Jane", LastName = "Appleseed" }; 36 | sut.FirstName = "Joe"; 37 | 38 | Assert.AreEqual("Joe Appleseed", sut.FullName); 39 | } 40 | 41 | [Test] 42 | public void FullNameUpdatesWhenLastNameChanges() 43 | { 44 | var sut = new PersonViewModel { FirstName = "Jane", LastName = "Appleseed" }; 45 | sut.LastName = "Smith"; 46 | 47 | Assert.AreEqual("Jane Smith", sut.FullName); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/Ex2.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Ex2.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vagrant Inc.")] 12 | [assembly: AssemblyProduct("Ex2.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Vagrant Inc. 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b5463a2f-f921-472a-acf1-c44d83fce768")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/Ex2.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/Ex2/PersonViewModel.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | 3 | namespace Ex2 4 | { 5 | public class PersonViewModel : ReactiveObject 6 | { 7 | public PersonViewModel() 8 | { 9 | _fullName = this.WhenAnyValue(vm => vm.FirstName, vm => vm.LastName, (f, l) => string.Format("{0} {1}", f, l)) 10 | .ToProperty(this, vm => vm.FullName); 11 | 12 | var firstAndLastFilled = this.WhenAnyValue(vm => vm.FirstName, vm => vm.LastName, 13 | (f, l) => !string.IsNullOrWhiteSpace(f) && !string.IsNullOrWhiteSpace(l)); 14 | ChangeName = ReactiveCommand.Create(firstAndLastFilled); 15 | } 16 | 17 | public readonly IReactiveCommand ChangeName; 18 | 19 | private readonly ObservableAsPropertyHelper _fullName; 20 | public string FullName 21 | { 22 | get { return _fullName.Value; } 23 | } 24 | 25 | private string _firstName; 26 | public string FirstName 27 | { 28 | get { return _firstName; } 29 | set { this.RaiseAndSetIfChanged(ref _firstName, value); } 30 | } 31 | 32 | private string _lastName; 33 | public string LastName 34 | { 35 | get { return _lastName; } 36 | set { this.RaiseAndSetIfChanged(ref _lastName, value); } 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/Ex2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Ex2")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vagrant Inc.")] 12 | [assembly: AssemblyProduct("Ex2")] 13 | [assembly: AssemblyCopyright("Copyright © Vagrant Inc. 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c7c35797-0198-4fce-822f-1231979824bd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/Ex2/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex2-reactivecommand-part1/ex2-reactivecommand-part1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex2.Tests", "Ex2.Tests\Ex2.Tests.csproj", "{7B54550F-D810-4F3B-B880-F87B990D5904}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex2", "Ex2\Ex2.csproj", "{C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /src/complete/ex3-reactivecommand-part2/Ex3.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Ex3.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vagrant Inc.")] 12 | [assembly: AssemblyProduct("Ex3.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Vagrant Inc. 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b5463a2f-f921-472a-acf1-c44d83fce768")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/complete/ex3-reactivecommand-part2/Ex3.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/complete/ex3-reactivecommand-part2/Ex3/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Ex3")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vagrant Inc.")] 12 | [assembly: AssemblyProduct("Ex3")] 13 | [assembly: AssemblyCopyright("Copyright © Vagrant Inc. 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c7c35797-0198-4fce-822f-1231979824bd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/complete/ex3-reactivecommand-part2/Ex3/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex3-reactivecommand-part2/ex3-reactivecommand-part2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex3", "Ex3\Ex3.csproj", "{C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex3.Tests", "Ex3.Tests\Ex3.Tests.csproj", "{7B54550F-D810-4F3B-B880-F87B990D5904}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {C50CA0FE-1323-4ED6-BB2B-AF123B4D3EE5}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {7B54550F-D810-4F3B-B880-F87B990D5904}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Ex4 2 | { 3 | public partial class App 4 | { 5 | public App() 6 | { 7 | var vm = new MainWindowModel(); 8 | var view = new MainWindow {ViewModel = vm}; 9 | 10 | view.ShowDialog(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 9 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | First Name: 28 | 29 | Last Name: 30 | 31 | 32 | 33 | 34 | 35 | Server Response: 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex4 5 | { 6 | public partial class MainWindow : IViewFor 7 | { 8 | public MainWindow() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => 13 | { 14 | d(this.Bind(ViewModel, vm => vm.FirstName, v => v.FirstName.Text)); 15 | d(this.Bind(ViewModel, vm => vm.LastName, v => v.LastName.Text)); 16 | d(this.OneWayBind(ViewModel, vm => vm.ServerResult, v => v.ServerResult.Text)); 17 | d(this.BindCommand(ViewModel, vm => vm.ChangeName, v => v.ChangeNameButton)); 18 | }); 19 | } 20 | 21 | public static readonly DependencyProperty ViewModelProperty; 22 | 23 | static MainWindow() 24 | { 25 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MainWindowModel), typeof(MainWindow)); 26 | } 27 | 28 | public MainWindowModel ViewModel 29 | { 30 | get { return (MainWindowModel)GetValue(ViewModelProperty); } 31 | set { SetValue(ViewModelProperty, value); } 32 | } 33 | 34 | object IViewFor.ViewModel 35 | { 36 | get { return ViewModel; } 37 | set { ViewModel = (MainWindowModel)value; } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/MainWindowModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using ReactiveUI; 4 | 5 | namespace Ex4 6 | { 7 | public class MainWindowModel : ReactiveObject 8 | { 9 | private async Task PretendToCallTheServer() 10 | { 11 | await Task.Delay(2000); 12 | return "Hello World"; 13 | } 14 | 15 | public MainWindowModel() 16 | { 17 | ServerResult = "Haven't talked to the server yet..."; 18 | 19 | var firstAndLastFilled = this.WhenAnyValue(vm => vm.FirstName, vm => vm.LastName, 20 | (f, l) => !string.IsNullOrWhiteSpace(f) && !string.IsNullOrWhiteSpace(l)); 21 | 22 | ChangeName = ReactiveCommand.CreateAsyncTask(firstAndLastFilled, _ => PretendToCallTheServer()); 23 | ChangeName.Subscribe(r => ServerResult = r); 24 | } 25 | 26 | private string _serverResult; 27 | public string ServerResult 28 | { 29 | get { return _serverResult; } 30 | set { this.RaiseAndSetIfChanged(ref _serverResult, value); } 31 | } 32 | 33 | public readonly ReactiveCommand ChangeName; 34 | 35 | private string _firstName; 36 | public string FirstName 37 | { 38 | get { return _firstName; } 39 | set { this.RaiseAndSetIfChanged(ref _firstName, value); } 40 | } 41 | 42 | private string _lastName; 43 | public string LastName 44 | { 45 | get { return _lastName; } 46 | set { this.RaiseAndSetIfChanged(ref _lastName, value); } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Ex4.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/Ex4/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex4-bindings-part1/ex4-bindings-part1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex4", "Ex4\Ex4.csproj", "{39BDFDD2-F246-4807-ADCB-30A1E44A52E2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Ex5 2 | { 3 | public partial class App 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | (new AppBootstrapper()).Bootstrap(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/AppBootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | using Splat; 3 | 4 | namespace Ex5 5 | { 6 | public class AppBootstrapper 7 | { 8 | public void Bootstrap() 9 | { 10 | ConfigureServiceLocator(); 11 | RunApp(); 12 | } 13 | 14 | private void ConfigureServiceLocator() 15 | { 16 | var sl = Locator.CurrentMutable; 17 | 18 | sl.Register(() => new TitleBarView(), typeof(IViewFor)); 19 | } 20 | 21 | private void RunApp() 22 | { 23 | var vm = new MainWindowModel(); 24 | var view = new MainWindow {ViewModel = vm}; 25 | 26 | view.ShowDialog(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/ControlStyles.ReactiveUI.xaml: -------------------------------------------------------------------------------- 1 |  4 | 9 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 10 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | First Name: 31 | 32 | Last Name: 33 | 34 | 35 | 36 | 37 | 38 | Server Response: 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex5 5 | { 6 | public partial class MainWindow : IViewFor 7 | { 8 | public MainWindow() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => 13 | { 14 | d(this.OneWayBind(ViewModel, vm => vm.TitleBar, v => v.TitleBarHost.ViewModel)); 15 | d(this.Bind(ViewModel, vm => vm.FirstName, v => v.FirstName.Text)); 16 | d(this.Bind(ViewModel, vm => vm.LastName, v => v.LastName.Text)); 17 | d(this.OneWayBind(ViewModel, vm => vm.ServerResult, v => v.ServerResult.Text)); 18 | d(this.BindCommand(ViewModel, vm => vm.ChangeName, v => v.ChangeNameButton)); 19 | }); 20 | } 21 | 22 | public static readonly DependencyProperty ViewModelProperty; 23 | 24 | static MainWindow() 25 | { 26 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MainWindowModel), typeof(MainWindow)); 27 | } 28 | 29 | public MainWindowModel ViewModel 30 | { 31 | get { return (MainWindowModel)GetValue(ViewModelProperty); } 32 | set { SetValue(ViewModelProperty, value); } 33 | } 34 | 35 | object IViewFor.ViewModel 36 | { 37 | get { return ViewModel; } 38 | set { ViewModel = (MainWindowModel)value; } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/MainWindowModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive.Linq; 3 | using System.Threading.Tasks; 4 | using ReactiveUI; 5 | 6 | namespace Ex5 7 | { 8 | public class MainWindowModel : ReactiveObject 9 | { 10 | private async Task PretendToCallTheServer() 11 | { 12 | await Task.Delay(2000); 13 | return "Hello World"; 14 | } 15 | 16 | public MainWindowModel() 17 | { 18 | TitleBar = new TitleBarViewModel(); 19 | 20 | ServerResult = "Haven't talked to the server yet..."; 21 | 22 | var firstAndLastFilled = this.WhenAnyValue(vm => vm.FirstName, vm => vm.LastName, 23 | (f, l) => !string.IsNullOrWhiteSpace(f) && !string.IsNullOrWhiteSpace(l)); 24 | 25 | ChangeName = ReactiveCommand.CreateAsyncTask(firstAndLastFilled, _ => PretendToCallTheServer()); 26 | ChangeName.Subscribe(r => ServerResult = r); 27 | } 28 | 29 | private TitleBarViewModel _titleBar; 30 | public TitleBarViewModel TitleBar 31 | { 32 | get { return _titleBar; } 33 | private set { this.RaiseAndSetIfChanged(ref _titleBar, value); } 34 | } 35 | 36 | private string _serverResult; 37 | public string ServerResult 38 | { 39 | get { return _serverResult; } 40 | set { this.RaiseAndSetIfChanged(ref _serverResult, value); } 41 | } 42 | 43 | public readonly ReactiveCommand ChangeName; 44 | 45 | private string _firstName; 46 | public string FirstName 47 | { 48 | get { return _firstName; } 49 | set { this.RaiseAndSetIfChanged(ref _firstName, value); } 50 | } 51 | 52 | private string _lastName; 53 | public string LastName 54 | { 55 | get { return _lastName; } 56 | set { this.RaiseAndSetIfChanged(ref _lastName, value); } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Ex5.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/TitleBarView.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/TitleBarView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex5 5 | { 6 | public partial class TitleBarView : IViewFor 7 | { 8 | public TitleBarView() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => d(this.OneWayBind(ViewModel, vm => vm.Title, v => v.Title.Text))); 13 | } 14 | 15 | public static readonly DependencyProperty ViewModelProperty; 16 | 17 | static TitleBarView() 18 | { 19 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(TitleBarViewModel), typeof(TitleBarView)); 20 | } 21 | 22 | public TitleBarViewModel ViewModel 23 | { 24 | get { return (TitleBarViewModel)GetValue(ViewModelProperty); } 25 | set { SetValue(ViewModelProperty, value); } 26 | } 27 | 28 | object IViewFor.ViewModel 29 | { 30 | get { return ViewModel; } 31 | set { ViewModel = (TitleBarViewModel)value; } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/TitleBarViewModel.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | 3 | namespace Ex5 4 | { 5 | public class TitleBarViewModel : ReactiveObject 6 | { 7 | public TitleBarViewModel() 8 | { 9 | Title = "This is being composed from TitleBarViewModel"; 10 | } 11 | 12 | private string _title; 13 | public string Title 14 | { 15 | get { return _title; } 16 | set { this.RaiseAndSetIfChanged(ref _title, value); } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/Ex5/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex5-viewmodel-composition/ex5-viewmodel-composition.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex5", "Ex5\Ex5.csproj", "{39BDFDD2-F246-4807-ADCB-30A1E44A52E2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Ex6 2 | { 3 | public partial class App 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | (new AppBootstrapper()).Bootstrap(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/AppBootstrapper.cs: -------------------------------------------------------------------------------- 1 | namespace Ex6 2 | { 3 | public class AppBootstrapper 4 | { 5 | public void Bootstrap() 6 | { 7 | RunApp(); 8 | } 9 | 10 | private void RunApp() 11 | { 12 | var vm = new MainWindowModel(); 13 | var view = new MainWindow {ViewModel = vm}; 14 | 15 | view.ShowDialog(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/ControlStyles.ReactiveUI.xaml: -------------------------------------------------------------------------------- 1 |  4 | 9 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 9 | 12 | 15 | 16 | 17 | 18 | Name: 19 | 20 | 21 | 22 | 23 | 24 | Entered Text: 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using ReactiveUI; 4 | 5 | namespace Ex6 6 | { 7 | public partial class MainWindow : IViewFor 8 | { 9 | public MainWindow() 10 | { 11 | InitializeComponent(); 12 | 13 | this.WhenActivated(d => 14 | { 15 | d(ViewModel.GreetUser.Subscribe(_ => 16 | MessageBox.Show(string.Format("Hello {0}", ViewModel.FirstName)))); 17 | 18 | d(this.Bind(ViewModel, vm => vm.FirstName, v => v.FirstName.Text)); 19 | d(this.BindCommand(ViewModel, vm => vm.GreetUser, v => v.GreetUserButton)); 20 | 21 | d(ViewModel.WhenAnyValue(vm => vm.FirstName).BindTo(this, v => v.WhatWasEntered.Text)); 22 | }); 23 | 24 | } 25 | 26 | public static readonly DependencyProperty ViewModelProperty; 27 | 28 | static MainWindow() 29 | { 30 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MainWindowModel), typeof(MainWindow)); 31 | } 32 | 33 | public MainWindowModel ViewModel 34 | { 35 | get { return (MainWindowModel)GetValue(ViewModelProperty); } 36 | set { SetValue(ViewModelProperty, value); } 37 | } 38 | 39 | object IViewFor.ViewModel 40 | { 41 | get { return ViewModel; } 42 | set { ViewModel = (MainWindowModel)value; } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/MainWindowModel.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | 3 | namespace Ex6 4 | { 5 | public class MainWindowModel : ReactiveObject 6 | { 7 | public MainWindowModel() 8 | { 9 | var canGreet = this.WhenAnyValue(vm => vm.FirstName, n => !string.IsNullOrWhiteSpace(n)); 10 | GreetUser = ReactiveCommand.Create(canGreet); 11 | } 12 | 13 | public readonly ReactiveCommand GreetUser; 14 | 15 | private string _firstName; 16 | public string FirstName 17 | { 18 | get { return _firstName; } 19 | set { this.RaiseAndSetIfChanged(ref _firstName, value); } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Ex6.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/Ex6/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex6-bindings-part2/ex6-bindings-part2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex6", "Ex6\Ex6.csproj", "{39BDFDD2-F246-4807-ADCB-30A1E44A52E2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Ex7 2 | { 3 | public partial class App 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | (new AppBootstrapper()).Bootstrap(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/AppBootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | using Splat; 3 | 4 | namespace Ex7 5 | { 6 | public class AppBootstrapper 7 | { 8 | public void Bootstrap() 9 | { 10 | ConfigureServiceLocator(); 11 | RunApp(); 12 | } 13 | 14 | private void ConfigureServiceLocator() 15 | { 16 | var sl = Locator.CurrentMutable; 17 | 18 | sl.Register(() => new TweetView(), typeof (IViewFor)); 19 | } 20 | 21 | private void RunApp() 22 | { 23 | var vm = new MainWindowModel(); 24 | var view = new MainWindow {ViewModel = vm}; 25 | 26 | view.ShowDialog(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/ControlStyles.ReactiveUI.xaml: -------------------------------------------------------------------------------- 1 |  4 | 9 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | Loading... 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex7 5 | { 6 | public partial class MainWindow : IViewFor 7 | { 8 | public MainWindow() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => 13 | { 14 | d(this.OneWayBind(ViewModel, vm => vm.Tweets, v => v.Tweets.ItemsSource)); 15 | d(this.BindCommand(ViewModel, vm => vm.RemoveTweet, v => v.RemoveTweet)); 16 | 17 | d(ViewModel.WhenAnyObservable(vm => vm.LoadTweets.IsExecuting) 18 | .BindTo(this, v => v.LoadingIndicator.Visibility)); 19 | 20 | ViewModel.LoadTweets.Execute(null); 21 | }); 22 | } 23 | 24 | public static readonly DependencyProperty ViewModelProperty; 25 | 26 | static MainWindow() 27 | { 28 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MainWindowModel), typeof(MainWindow)); 29 | } 30 | 31 | public MainWindowModel ViewModel 32 | { 33 | get { return (MainWindowModel)GetValue(ViewModelProperty); } 34 | set { SetValue(ViewModelProperty, value); } 35 | } 36 | 37 | object IViewFor.ViewModel 38 | { 39 | get { return ViewModel; } 40 | set { ViewModel = (MainWindowModel)value; } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/MainWindowModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive.Linq; 3 | using System.Threading.Tasks; 4 | using ReactiveUI; 5 | 6 | namespace Ex7 7 | { 8 | public class MainWindowModel : ReactiveObject 9 | { 10 | public MainWindowModel() 11 | { 12 | Tweets = new ReactiveList(); 13 | 14 | LoadTweets = ReactiveCommand.CreateAsyncTask(async _ => 15 | { 16 | await Task.Delay(2000); 17 | foreach (var t in FakeData.GetFakeTweets()) 18 | Tweets.Add(t); 19 | }); 20 | 21 | var canRemoveTweet = this.WhenAnyValue(vm => vm.Tweets.Count) 22 | .Select(c => c > 0); 23 | 24 | RemoveTweet = ReactiveCommand.Create(canRemoveTweet); 25 | RemoveTweet.Subscribe(_ => Tweets.RemoveAt(0)); 26 | } 27 | 28 | public IReactiveCommand LoadTweets { get; private set; } 29 | public ReactiveCommand RemoveTweet { get; private set; } 30 | 31 | public ReactiveList Tweets { get; private set; } 32 | } 33 | } -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Ex7.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/TweetView.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/TweetView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex7 5 | { 6 | public partial class TweetView : IViewFor 7 | { 8 | public TweetView() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => 13 | { 14 | d(this.OneWayBind(ViewModel, vm => vm.UserHandle, v => v.UserHandle.Text)); 15 | d(this.OneWayBind(ViewModel, vm => vm.Date, v => v.TweetDate.Text, date => date.ToString("dd-MMM HH:mm:ss"))); 16 | d(this.OneWayBind(ViewModel, vm => vm.Message, v => v.Message.Text)); 17 | }); 18 | } 19 | 20 | public static readonly DependencyProperty ViewModelProperty; 21 | 22 | static TweetView() 23 | { 24 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(TweetViewModel), typeof(TweetView)); 25 | } 26 | 27 | public TweetViewModel ViewModel 28 | { 29 | get { return (TweetViewModel)GetValue(ViewModelProperty); } 30 | set { SetValue(ViewModelProperty, value); } 31 | } 32 | 33 | object IViewFor.ViewModel 34 | { 35 | get { return ViewModel; } 36 | set { ViewModel = (TweetViewModel)value; } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/TweetViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ReactiveUI; 3 | 4 | namespace Ex7 5 | { 6 | public class TweetViewModel : ReactiveObject 7 | { 8 | private string _userHandle; 9 | public string UserHandle 10 | { 11 | get { return _userHandle; } 12 | set { this.RaiseAndSetIfChanged(ref _userHandle, value); } 13 | } 14 | 15 | private string _message; 16 | public string Message 17 | { 18 | get { return _message; } 19 | set { this.RaiseAndSetIfChanged(ref _message, value); } 20 | } 21 | 22 | private DateTime _date; 23 | public DateTime Date 24 | { 25 | get { return _date; } 26 | set { this.RaiseAndSetIfChanged(ref _date, value); } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/Ex7/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex7-bindings-part3/ex7-bindings-part3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex7", "Ex7\Ex7.csproj", "{39BDFDD2-F246-4807-ADCB-30A1E44A52E2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {39BDFDD2-F246-4807-ADCB-30A1E44A52E2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Ex8 2 | { 3 | public partial class App 4 | { 5 | public App() 6 | { 7 | var bootstrapper = new AppBootstrapper(); 8 | bootstrapper.Run(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/AppBootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | using Splat; 3 | 4 | namespace Ex8 5 | { 6 | public class AppBootstrapper 7 | { 8 | public void Run() 9 | { 10 | RegisterViews(); 11 | var vm = MakeAndRegisterMainViewModel(); 12 | var view = new MainWindowView {ViewModel = vm}; 13 | view.Show(); 14 | } 15 | 16 | private MainWindowViewModel MakeAndRegisterMainViewModel() 17 | { 18 | var vm = new MainWindowViewModel(); 19 | Locator.CurrentMutable.RegisterConstant(vm, typeof(IScreen)); 20 | return vm; 21 | } 22 | 23 | private void RegisterViews() 24 | { 25 | var ioc = Locator.CurrentMutable; 26 | 27 | ioc.Register(() => new ViewA(), typeof (IViewFor)); 28 | ioc.Register(() => new ViewB(), typeof(IViewFor)); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/MainWindowView.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | README: Click the "Navigate to A" and "Navigate to B" buttons 14 | a few times and watch the view and viewmodel numbers incremease. Then start 15 | going back instead, and see that while the ViewModels are treated as a stack 16 | there's a new view created each time. In other words, stateful VIEWS are 17 | a Bad Plan. 18 | 19 | 20 | 21 | 22 | Nothing to see here... 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/MainWindowView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex8 5 | { 6 | public partial class MainWindowView : IViewFor 7 | { 8 | public MainWindowView() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => 13 | { 14 | d(this.Bind(ViewModel, vm => vm.Router, v => v.ViewHost.Router)); 15 | 16 | d(this.BindCommand(ViewModel, vm => vm.NavigateToACommand, v => v.NavigateToA)); 17 | d(this.BindCommand(ViewModel, vm => vm.NavigateToBCommand, v => v.NavigateToB)); 18 | d(this.BindCommand(ViewModel, vm => vm.BackCommand, v => v.BackButton)); 19 | }); 20 | } 21 | 22 | static MainWindowView() 23 | { 24 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MainWindowViewModel), typeof(MainWindowView)); 25 | } 26 | 27 | public static readonly DependencyProperty ViewModelProperty; 28 | 29 | public MainWindowViewModel ViewModel 30 | { 31 | get { return (MainWindowViewModel)GetValue(ViewModelProperty); } 32 | set { SetValue(ViewModelProperty, value); } 33 | } 34 | 35 | object IViewFor.ViewModel 36 | { 37 | get { return ViewModel; } 38 | set { ViewModel = (MainWindowViewModel)value; } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive.Linq; 3 | using ReactiveUI; 4 | 5 | namespace Ex8 6 | { 7 | public class MainWindowViewModel : ReactiveObject, IScreen 8 | { 9 | public RoutingState Router { get; private set; } 10 | 11 | public ReactiveCommand NavigateToACommand { get; private set; } 12 | public ReactiveCommand NavigateToBCommand { get; private set; } 13 | public ReactiveCommand BackCommand { get; private set; } 14 | 15 | public MainWindowViewModel() 16 | { 17 | Router = new RoutingState(); 18 | 19 | var canGoBack = this.WhenAnyValue(vm => vm.Router.NavigationStack.Count) 20 | .Select(count => count > 0); 21 | 22 | NavigateToACommand = ReactiveCommand.Create(); 23 | NavigateToBCommand = ReactiveCommand.Create(); 24 | BackCommand = ReactiveCommand.Create(canGoBack); 25 | 26 | NavigateToACommand.Subscribe(NavigateToA); 27 | NavigateToBCommand.Subscribe(NavigateToB); 28 | BackCommand.Subscribe(NavigateBack); 29 | } 30 | 31 | public void NavigateBack(object _) 32 | { 33 | Router.NavigateBack.Execute(null); 34 | } 35 | 36 | public void NavigateToA(object _) 37 | { 38 | Router.Navigate.Execute(new ViewModelA(this)); 39 | } 40 | 41 | public void NavigateToB(object _) 42 | { 43 | Router.Navigate.Execute(new ViewModelB(this)); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Windows; 4 | 5 | [assembly: AssemblyTitle("Ex8")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("Ex8")] 10 | [assembly: AssemblyCopyright("Copyright © 2014")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: ThemeInfo( 17 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 18 | //(used if a resource is not found in the page, or application resource dictionaries) 19 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 20 | //(used if a resource is not found in the page, app, or any theme specific resource dictionaries) 21 | )] 22 | 23 | [assembly: AssemblyVersion("1.0.0.0")] 24 | [assembly: AssemblyFileVersion("1.0.0.0")] 25 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Ex8.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewA.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | View: 8 | VM: 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewA.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive.Linq; 3 | using System.Windows; 4 | using ReactiveUI; 5 | 6 | namespace Ex8 7 | { 8 | public partial class ViewA : IViewFor 9 | { 10 | public ViewA() 11 | { 12 | InitializeComponent(); 13 | 14 | ViewInstanceCount.Increment(); 15 | ViewInstanceId.Text = ViewInstanceCount.InstanceCount; 16 | 17 | this.WhenActivated(d => 18 | { 19 | d(this.Bind(ViewModel, vm => vm.ViewModelInstanceId, v => v.ViewModelInstanceId.Text)); 20 | 21 | d(this.WhenAnyValue(v => v.ViewModel) 22 | .Where(v => v != null) 23 | .Subscribe(vm => vm.GetDataAndStuffCommand.Execute(null))); 24 | }); 25 | } 26 | 27 | static ViewA() 28 | { 29 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(ViewModelA), typeof(ViewA)); 30 | } 31 | 32 | public static readonly DependencyProperty ViewModelProperty; 33 | 34 | public ViewModelA ViewModel 35 | { 36 | get { return (ViewModelA)GetValue(ViewModelProperty); } 37 | set { SetValue(ViewModelProperty, value); } 38 | } 39 | 40 | object IViewFor.ViewModel 41 | { 42 | get { return ViewModel; } 43 | set { ViewModel = (ViewModelA)value; } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewB.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | View: 7 | VM: 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewB.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive.Linq; 3 | using System.Windows; 4 | using ReactiveUI; 5 | 6 | namespace Ex8 7 | { 8 | public partial class ViewB : IViewFor 9 | { 10 | public ViewB() 11 | { 12 | InitializeComponent(); 13 | 14 | ViewInstanceCount.Increment(); 15 | ViewInstanceId.Text = ViewInstanceCount.InstanceCount; 16 | 17 | this.WhenActivated(d => 18 | { 19 | d(this.Bind(ViewModel, vm => vm.ViewModelInstanceId, v => v.ViewModelInstanceId.Text)); 20 | 21 | d(this.WhenAnyValue(v => v.ViewModel) 22 | .Where(v => v != null) 23 | .Subscribe(vm => vm.GetDataAndStuffCommand.Execute(null))); 24 | }); 25 | } 26 | 27 | public static readonly DependencyProperty ViewModelProperty = 28 | DependencyProperty.Register("ViewModel", typeof(ViewModelB), typeof(ViewB)); 29 | 30 | public ViewModelB ViewModel 31 | { 32 | get { return (ViewModelB)GetValue(ViewModelProperty); } 33 | set { SetValue(ViewModelProperty, value); } 34 | } 35 | 36 | object IViewFor.ViewModel 37 | { 38 | get { return ViewModel; } 39 | set { ViewModel = (ViewModelB)value; } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewInstanceCount.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Ex8 4 | { 5 | /// 6 | /// Such thread safety. 7 | /// 8 | public static class ViewInstanceCount 9 | { 10 | private static int _instanceCount; 11 | 12 | public static string InstanceCount 13 | { 14 | get { return _instanceCount.ToString(CultureInfo.InvariantCulture); } 15 | } 16 | 17 | public static void Increment() 18 | { 19 | _instanceCount++; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewModelA.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ReactiveUI; 3 | using Splat; 4 | 5 | namespace Ex8 6 | { 7 | public class ViewModelA : ReactiveObject, IRoutableViewModel 8 | { 9 | public ViewModelA(IScreen hostScreen) 10 | { 11 | HostScreen = hostScreen; 12 | 13 | ViewModelInstanceCount.Increment(); 14 | ViewModelInstanceId = ViewModelInstanceCount.InstanceCount; 15 | 16 | //NOTE: although it's very tempting to use this.WhenNavigatedTo() to 17 | // prime data and stuff, don't do that, only use it for the purposes 18 | // of aquiring and releasing disposable resources. For example, it's 19 | // reasonable to use it to acquire a subscription to hot observables 20 | // where the subscription is required while the view this view model 21 | // reprents is actually on screen. 22 | // 23 | // Instead, define a ReactiveCommand which does the work and trigger 24 | // it when the view model is attached to the view. Look at the ViewA 25 | // constructor for how to trigger this command. 26 | GetDataAndStuffCommand = ReactiveCommand.Create(); 27 | GetDataAndStuffCommand.Subscribe(_ => this.Log().Info("GettingDataAndStuff in ViewModel A")); 28 | } 29 | 30 | public string ViewModelInstanceId { get; private set; } 31 | 32 | public ReactiveCommand GetDataAndStuffCommand { get; private set; } 33 | 34 | public string UrlPathSegment { get { return "something"; } } 35 | public IScreen HostScreen { get; private set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewModelB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ReactiveUI; 3 | using Splat; 4 | 5 | namespace Ex8 6 | { 7 | public class ViewModelB : ReactiveObject, IRoutableViewModel 8 | { 9 | public ViewModelB(IScreen hostScreen) 10 | { 11 | HostScreen = hostScreen; 12 | 13 | ViewModelInstanceCount.Increment(); 14 | ViewModelInstanceId = ViewModelInstanceCount.InstanceCount; 15 | 16 | //NOTE: although it's very tempting to use this.WhenNavigatedTo() to 17 | // prime data and stuff, don't do that, only use it for the purposes 18 | // of aquiring and releasing disposable resources. For example, it's 19 | // reasonable to use it to acquire a subscription to hot observables 20 | // where the subscription is required while the view this view model 21 | // reprents is actually on screen. 22 | // 23 | // Instead, define a ReactiveCommand which does the work and trigger 24 | // it when the view model is attached to the view. Look at the ViewB 25 | // constructor for how to trigger this command. 26 | GetDataAndStuffCommand = ReactiveCommand.Create(); 27 | GetDataAndStuffCommand.Subscribe(_ => this.Log().Info("GettingDataAndStuff in ViewModel B")); 28 | } 29 | 30 | public string ViewModelInstanceId { get; private set; } 31 | 32 | public ReactiveCommand GetDataAndStuffCommand { get; private set; } 33 | 34 | public string UrlPathSegment { get { return "somethingelse"; } } 35 | public IScreen HostScreen { get; private set; } 36 | } 37 | } -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/ViewModelInstanceCount.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Ex8 4 | { 5 | /// 6 | /// Such thread safety. 7 | /// 8 | public static class ViewModelInstanceCount 9 | { 10 | private static int _instanceCount; 11 | 12 | public static string InstanceCount 13 | { 14 | get { return _instanceCount.ToString(CultureInfo.InvariantCulture); } 15 | } 16 | 17 | public static void Increment() 18 | { 19 | _instanceCount++; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/complete/ex8-routing/Ex8/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/complete/ex8-routing/ex8-routing.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex8", "Ex8\Ex8.csproj", "{6DD6150D-0EDF-4829-8EA4-72C49A244AAA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6DD6150D-0EDF-4829-8EA4-72C49A244AAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {6DD6150D-0EDF-4829-8EA4-72C49A244AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {6DD6150D-0EDF-4829-8EA4-72C49A244AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {6DD6150D-0EDF-4829-8EA4-72C49A244AAA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | using Splat; 3 | 4 | namespace Ex9 5 | { 6 | public partial class App 7 | { 8 | public App() 9 | { 10 | Locator.CurrentMutable.Register(() => new TestView(), typeof(IViewFor)); 11 | 12 | var vm = new MainWindowModel(); 13 | var view = new MainWindow {ViewModel = vm}; 14 | view.Show(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ReactiveUI; 3 | 4 | namespace Ex9 5 | { 6 | public partial class MainWindow : IViewFor 7 | { 8 | public MainWindow() 9 | { 10 | InitializeComponent(); 11 | 12 | this.WhenActivated(d => 13 | { 14 | d(this.OneWayBind(ViewModel, vm => vm.TestViewModels, v=> v.TestModels.ItemsSource)); 15 | ViewModel.SetUpDataCommand.Execute(null); 16 | }); 17 | } 18 | 19 | public static readonly DependencyProperty ViewModelProperty; 20 | 21 | static MainWindow() 22 | { 23 | ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MainWindowModel), typeof(MainWindow)); 24 | } 25 | 26 | public MainWindowModel ViewModel 27 | { 28 | get { return (MainWindowModel)GetValue(ViewModelProperty); } 29 | set { SetValue(ViewModelProperty, value); } 30 | } 31 | 32 | object IViewFor.ViewModel 33 | { 34 | get { return ViewModel; } 35 | set { ViewModel = (MainWindowModel)value; } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/MainWindowModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using ReactiveUI; 4 | 5 | namespace Ex9 6 | { 7 | public class MainWindowModel : ReactiveObject 8 | { 9 | private readonly TestDataSource _testDataSource; 10 | 11 | public MainWindowModel() 12 | { 13 | _testDataSource = new TestDataSource(); 14 | TestModels = new ReactiveList(); 15 | 16 | TestViewModels = TestModels.CreateDerivedCollection(m => 17 | { 18 | var vm = new TestViewModel 19 | { 20 | Id = m.Id, 21 | Name = m.Name, 22 | OtherValue = "", 23 | OriginalModel = m 24 | }; 25 | vm.DoStuffWithThisCommand.Subscribe(x => DoStuff(x as TestViewModel)); 26 | return vm; 27 | }, m => true, (m, vm) => 0); 28 | 29 | SetUpDataCommand = ReactiveCommand.CreateAsyncTask(_ => _testDataSource.GetTests()); 30 | SetUpDataCommand.Subscribe(results => 31 | { 32 | using (SuppressChangeNotifications()) 33 | { 34 | TestModels.Clear(); 35 | foreach (var model in results) 36 | TestModels.Add(model); 37 | } 38 | }); 39 | } 40 | 41 | private void DoStuff(TestViewModel vm) 42 | { 43 | TestModels.Remove(vm.OriginalModel); 44 | } 45 | 46 | public IReactiveDerivedList TestViewModels { get; private set; } 47 | 48 | public ReactiveList TestModels { get; private set; } 49 | 50 | public ReactiveCommand> SetUpDataCommand { get; private set; } 51 | } 52 | } -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Ex9.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/TestDataSource.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | 5 | namespace Ex9 6 | { 7 | public class TestDataSource 8 | { 9 | public async Task> GetTests() 10 | { 11 | await Task.Delay(2000); 12 | return GetModels(); 13 | } 14 | 15 | private IEnumerable GetModels() 16 | { 17 | return Enumerable.Range(0, 10).Select(number => new TestModel { Id = number, Name = "Model Number " + number }); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/TestModel.cs: -------------------------------------------------------------------------------- 1 | namespace Ex9 2 | { 3 | public class TestModel 4 | { 5 | public string Name { get; set; } 6 | public int Id { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/complete/ex9-derivedlists/Ex9/TestView.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |