Skip to content

Commit 3aa6208

Browse files
author
Sam Storie
committed
Added some comments for myself later on :)
1 parent 7912e00 commit 3aa6208

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

reactiveui-simple-user-control/SimpleApp/SimpleApp/App.xaml.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ public partial class App : Application
2121
{
2222
public App()
2323
{
24-
// This is the "magic" that automatically registers each view against the IViewFor<>
25-
// interface it implements. This is specific to Splat, and could be replaced by the
26-
// specific capabilities of another IoC library
27-
//
2824
var assembly = Assembly.GetExecutingAssembly();
2925
var builder = new ContainerBuilder();
3026

27+
// Since we're using the ReactiveUI.Autofac library this is all we need to do
28+
// to wire up our views and view models. Since it's based on Autofac we can
29+
// also freely inject any dependencies we've registered.
30+
//
3131
builder.RegisterForReactiveUI(assembly);
3232
RxAppAutofacExtension.UseAutofacDependencyResolver(builder.Build());
3333

34+
// We've replaced Splat's default locator with the Autofac version so
35+
// we can continue to use the code shown in the ReactiveUI examples
36+
//
3437
var view = (Views.MainWindow)Locator.CurrentMutable.GetService(typeof(IViewFor<MainWindowViewModel>));
3538
view.Show();
3639
}

reactiveui-simple-user-control/SimpleApp/SimpleApp/Views/MainWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="CurrentValue" FontSize="48"></TextBlock>
2121
</DockPanel>
2222

23+
<!-- This is the "magic" that allows ViewModel-first controls to work. -->
24+
<!-- By using the VMVH from ReactiveUI we can let the library automatically -->
25+
<!-- resolve the required view for us. The downside is we seem to lose any -->
26+
<!-- design-time view of the actual control here in the parent window. -->
2327
<reactiveUi:ViewModelViewHost Grid.Row="1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" x:Name="CounterViewModel"></reactiveUi:ViewModelViewHost>
2428
</Grid>
2529
</Window>

0 commit comments

Comments
 (0)