This is the repository for the excercises for the "Building Reactive User Interfaces" session at the 2014 Progressive .NET Tutorials hosted at SkillsMatter. We are using a ReactiveUI 5.5.1 from NuGet, which is the current stable released version. Reactive UI 6 will hit soon, at which point I'll go through and update this repository accordingly.
There are few steps which are optional but may considerably improve your experience when developing using WPF and ReactiveUI in Visual Studio.
-
Install the snippets from the
snippetsdirectory. This significantly reduces the amount of boilerplate code you have to write. You could also use ReSharper snippets instead of native Visual Studio ones, which may work even better.- Select Tools -> Code Snippets Manager from the main menu
- Ensure "Visual C#" is selected from the Language combo box
- Click the Add button and navigate to the
snippetsdirectory in this repository - Click OK to close the dialog
-
Ensure Visual Studio is set up to use the Source Code Editor for XAML files. This has been observed on a number of machines to signficantly reduce the number of crashes during editing, especially if ReSharper is installed. To change this:
- Right-click a XAML file in the solution explorer and select Open With
- Select Source Code (Text) Editor from the list, and click Set as Default
- Click OK to close the dialog
- Open the package manager console window
- Issue the following command:
Install-Package reactiveui
This exercise will take you through completing the implementation of a basic ViewModel deriving from ReactiveObject. It will have two properties FirstName and LastName, and update a read-only property named FullName when either of these change.
- Open the solution
ex1-readonlyproperties.slnin Visual Studio. Note that the solution does not build at this stage, as there are several definitions missing. - Read through the tests in
PersonViewModelTests.cs. - Write code in
PersonViewModel.csto add a read-write propertyLastName.
Hint: theraspropsnippet may be useful here! - Write code in
PersonViewModel.csto add a read-only propertyFullName.
Hint: theropropsnippet may be useful here! - Build the project and run the tests. Notice that the tests currently fail.
- Add code to the constructor of
PersonViewModelto set up theFullNameproperty to make the tests pass.
This excercise will take you through adding an IReactiveCommand to the ViewModel from exercise 1, and ensuring that the command can only be executed if both FirstName and LastName.