Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken links, document Avalonia type-safe bindings usage #298

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions input/docs/guidelines/platform/windows-forms.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Windows Forms

Ensure that you install `reactiveui.winforms` into your application.
Ensure that you install `ReactiveUI.WinForms` into your application.

Your viewmodels should inherit from `ReactiveObject`

Expand All @@ -13,11 +13,11 @@ Use `ISupportsActivation` and `WhenActivated` for lifecycle

Keep references to your subscriptions

- https://reactiveui.net/docs/concepts/reactive-programming/subscriptions#lifecycle
- https://reactiveui.net/docs/reactive-programming#lifecycle

Use disposables to manage lifetime, scope and resources:

- https://reactiveui.net/docs/concepts/reactive-programming/disposables
- https://reactiveui.net/docs/reactive-programming#disposables

Don't use eventhandlers, use the extension methods shipped in `reactiveui.events.winforms` instead

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Title: Windows Presentation Framework
---

Ensure that you install `reactiveui.wpf` into your application.
Ensure that you install `ReactiveUI.WPF` into your application.

Your viewmodels should inherit from `ReactiveObject`

Expand Down
4 changes: 2 additions & 2 deletions input/docs/guidelines/platform/windows-universal-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Use `ISupportsActivation` and `WhenActivated` for lifecycle

Keep references to your subscriptions

- https://reactiveui.net/docs/concepts/reactive-programming/subscriptions#lifecycle
- https://reactiveui.net/docs/reactive-programming#lifecycle

Use disposables to manage lifetime, scope and resources:

- https://reactiveui.net/docs/concepts/reactive-programming/disposables
- https://reactiveui.net/docs/reactive-programming#disposables

Don't use eventhandlers, use the extension methods shipped in `reactiveui.events` instead

Expand Down
8 changes: 5 additions & 3 deletions input/docs/guidelines/platform/xamarin-android.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Title: Xamarin Android
---

Ensure that you install `ReactiveUI.AndroidSupport` into your applications.

Your viewmodels should inherit from `ReactiveObject`

- https://reactiveui.net/api/reactiveui/reactiveobject/

Use wireupcontrols
Use `WireUpControls`

- https://reactiveui.net/docs/handbook/data-binding/xamarin-android/wire-up-controls

Expand All @@ -16,11 +18,11 @@ Use `ISupportsActivation` and `WhenActivated` for lifecycle

Keep references to your subscriptions

- https://reactiveui.net/docs/concepts/reactive-programming/subscriptions#lifecycle
- https://reactiveui.net/docs/reactive-programming#lifecycle

Use disposables to manage lifetime, scope and resources:

- https://reactiveui.net/docs/concepts/reactive-programming/disposables
- https://reactiveui.net/docs/reactive-programming#disposables

Don't use eventhandlers, use the extension methods shipped in `reactiveui.events` instead

Expand Down
8 changes: 4 additions & 4 deletions input/docs/guidelines/platform/xamarin-forms.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Title: Xamarin Forms
---

Ensure that you install `reactiveui.xamforms` into your applications.
Ensure that you install `ReactiveUI.XamForms` into your applications.

Your viewmodels should inherit from `ReactiveObject`

- https://reactiveui.net/api/reactiveui/reactiveobject/

Use wireupcontrols
Use `WireUpControls`

- https://reactiveui.net/docs/handbook/data-binding/xamarin-android/wire-up-controls

Expand All @@ -18,11 +18,11 @@ Use `ISupportsActivation` and `WhenActivated` for lifecycle

Keep references to your subscriptions

- https://reactiveui.net/docs/concepts/reactive-programming/subscriptions#lifecycle
- https://reactiveui.net/docs/reactive-programming#lifecycle

Use disposables to manage lifetime, scope and resources:

- https://reactiveui.net/docs/concepts/reactive-programming/disposables
- https://reactiveui.net/docs/reactive-programming#disposables

Don't use eventhandlers, use the extension methods shipped in `reactiveui.events.xamforms` instead

Expand Down
4 changes: 2 additions & 2 deletions input/docs/guidelines/platform/xamarin-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Use `ISupportsActivation` and `WhenActivated` for lifecycle

Keep references to your subscriptions

- https://reactiveui.net/docs/concepts/reactive-programming/subscriptions#lifecycle
- https://reactiveui.net/docs/reactive-programming#lifecycle

Use disposables to manage lifetime, scope and resources:

- https://reactiveui.net/docs/concepts/reactive-programming/disposables
- https://reactiveui.net/docs/reactive-programming#disposables

Don't use eventhandlers, use the extension methods shipped in `reactiveui.events` instead

Expand Down
4 changes: 2 additions & 2 deletions input/docs/guidelines/platform/xamarin-mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Use `ISupportsActivation` and `WhenActivated` for lifecycle

Keep references to your subscriptions

- https://reactiveui.net/docs/concepts/reactive-programming/subscriptions#lifecycle
- https://reactiveui.net/docs/reactive-programming#lifecycle

Use disposables to manage lifetime, scope and resources:

- https://reactiveui.net/docs/concepts/reactive-programming/disposables
- https://reactiveui.net/docs/reactive-programming#disposables

Don't use eventhandlers, use the extension methods shipped in `reactiveui.events` instead

Expand Down
33 changes: 29 additions & 4 deletions input/docs/handbook/data-binding/avalonia.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
For [WhenActivated](../when-activated) to work, you need to use custom base classes from `Avalonia.ReactiveUI` package, such as `ReactiveWindow<TViewModel>` or `ReactiveUserControl<TViewModel>`. Of course, you can also implement the `IViewFor<TViewModel>` interface by hand in your class, but ensure to store the `ViewModel` inside an `AvaloniaProperty`. [Activation and deactivation](../when-activated) feature will work for your view model only in case you put an empty `WhenActivated` block right before a call to `AvaloniaXamlRenderer.Load(this)` (otherwise activation can skip the Avalonia `Loaded` event alternative). See an example:
For [WhenActivated](../when-activated) to work, you need to use custom base classes from `Avalonia.ReactiveUI` package, such as `ReactiveWindow<TViewModel>` or `ReactiveUserControl<TViewModel>`. Of course, you can also implement the `IViewFor<TViewModel>` interface by hand in your class, but ensure to store the `ViewModel` inside an `AvaloniaProperty`. [Activation and deactivation](../when-activated) feature will work for your view model only in case you put an empty `WhenActivated` block right before a call to `AvaloniaXamlRenderer.Load(this)`. See an example:

```cs
// Activatable ViewModel.
public class ViewModel : ReactiveObject, ISupportsActivation
{
public ViewModelActivator Activator { get; }
Expand All @@ -18,11 +17,16 @@ public class ViewModel : ReactiveObject, ISupportsActivation
```

```xml
<Window>
<Window xmlns="https://github.com/avaloniaui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Background="#f0f0f0" FontFamily="Ubuntu"
MinHeight="590" MinWidth="750">
<TextBlock Text="Hello, world!" />
</Window>
```

Remember to place a call to WhenActivated to code-behind of the view, otherwise your view model's WhenActivated block won't get called.

```cs
public partial class View : ReactiveWindow<ViewModel>
{
Expand All @@ -35,4 +39,25 @@ public partial class View : ReactiveWindow<ViewModel>
}
```

Unfortunately, Avalonia XAML rendering engine won't generate strongly type `x:Name` references to controls for you, so the only way for now is to use the `FindControl` method that will find a control with specified name, or to use `{Binding Path}` syntax. But handling interactions, events and activation in the `WhenActivated` block is still a nice reason to use `IViewFor`.
Unfortunately, Avalonia XAML rendering engine won't generate strongly typed `x:Name` references to controls, so the only way for now is to use the `FindControl` method that will find a control by the name specified in XAML, or to use `{Binding Path}` syntax.

> **Note** The `FindControl` method shouldn't be used inside an expression. Instead, create a custom property which calls the `FindControl` method, or store the control in a variable. See an example of how to use ReactiveUI type-safe bindings with AvaloniaUI.

```cs
public partial class View : ReactiveWindow<ViewModel>
{
// Assume the Button control has the Name="ExampleButton" attribute defined in XAML.
public Button ExampleButton => this.FindControl<Button>("ExampleButton");

public View()
{
this.WhenActivated(disposables =>
{
// Bind the 'ExampleCommand' to 'ExampleButton' defined above.
this.BindCommand(ViewModel, x => x.ExampleCommand, x => x.ExampleButton)
.DisposeWith(disposables);
});
AvaloniaXamlLoader.Load(this);
}
}
```