forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactiveTextCell.cs
More file actions
44 lines (38 loc) · 1.4 KB
/
ReactiveTextCell.cs
File metadata and controls
44 lines (38 loc) · 1.4 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using ReactiveUI;
using Xamarin.Forms;
namespace ReactiveUI.XamForms
{
public class ReactiveTextCell<TViewModel> : TextCell, IViewFor<TViewModel>
where TViewModel : class
{
public static readonly BindableProperty ViewModelProperty = BindableProperty.Create(
nameof(ViewModel),
typeof(TViewModel),
typeof(ReactiveTextCell<TViewModel>),
default(TViewModel),
BindingMode.OneWay,
propertyChanged: OnViewModelChanged);
public TViewModel ViewModel
{
get { return (TViewModel)GetValue(ViewModelProperty); }
set { SetValue(ViewModelProperty, value); }
}
object IViewFor.ViewModel
{
get { return this.ViewModel; }
set { this.ViewModel = (TViewModel)value; }
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
this.ViewModel = this.BindingContext as TViewModel;
}
private static void OnViewModelChanged(BindableObject bindableObject, object oldValue, object newValue)
{
bindableObject.BindingContext = newValue;
}
}
}