Révision e837cdf1 GES_PAC/View/Controls/ChamberButtonView.xaml.cs
GES_PAC/View/Controls/ChamberButtonView.xaml.cs | ||
---|---|---|
1 |
using GES_PAC.ViewModel.Controls; |
|
1 |
using GES_PAC.ViewModel; |
|
2 |
using GES_PAC.ViewModel.Controls; |
|
2 | 3 |
|
3 |
namespace GES_PAC.View.Controls |
|
4 |
namespace GES_PAC.View.Controls; |
|
5 |
|
|
6 |
public partial class ChamberButtonView : ContentView |
|
4 | 7 |
{ |
5 |
public partial class ChamberButtonView : ContentView |
|
8 |
public static readonly BindableProperty ChamberIdProperty = |
|
9 |
BindableProperty.Create(nameof(ChamberId), typeof(int), typeof(ChamberButtonView), default(int), propertyChanged: OnChamberIdChanged); |
|
10 |
|
|
11 |
public static readonly BindableProperty TimerProperty = |
|
12 |
BindableProperty.Create(nameof(Timer), typeof(TimerPublisher), typeof(ChamberButtonView), propertyChanged: OnTimerChanged); |
|
13 |
|
|
14 |
public TimerPublisher? Timer |
|
15 |
{ |
|
16 |
get => (TimerPublisher?)GetValue(TimerProperty); |
|
17 |
set => SetValue(TimerProperty, value); |
|
18 |
} |
|
19 |
|
|
20 |
public int ChamberId |
|
21 |
{ |
|
22 |
get => (int)GetValue(ChamberIdProperty); |
|
23 |
set => SetValue(ChamberIdProperty, value); |
|
24 |
} |
|
25 |
public ChamberButtonView() |
|
26 |
{ |
|
27 |
InitializeComponent(); |
|
28 |
} |
|
29 |
|
|
30 |
protected override void OnBindingContextChanged() |
|
6 | 31 |
{ |
7 |
public static readonly BindableProperty ChamberIdProperty = |
|
8 |
BindableProperty.Create(nameof(ChamberId), typeof(int), typeof(ChamberButtonView), default(int), propertyChanged: OnChamberIdChanged); |
|
32 |
base.OnBindingContextChanged(); |
|
9 | 33 |
|
10 |
public int ChamberId
|
|
34 |
if (BindingContext is not ChamberButtonViewModel && ChamberId != 0 && Timer != null)
|
|
11 | 35 |
{ |
12 |
get => (int)GetValue(ChamberIdProperty);
|
|
13 |
set => SetValue(ChamberIdProperty, value);
|
|
36 |
var vm = new ChamberButtonViewModel(ChamberId, Timer);
|
|
37 |
BindingContext = vm;
|
|
14 | 38 |
} |
39 |
} |
|
40 |
private static void OnChamberIdChanged(BindableObject bindable, object oldValue, object newValue) |
|
41 |
{ |
|
42 |
var control = (ChamberButtonView)bindable; |
|
43 |
int id = (int)newValue; |
|
15 | 44 |
|
16 |
public ChamberButtonView()
|
|
45 |
if (control.BindingContext is ChamberButtonViewModel vm)
|
|
17 | 46 |
{ |
18 |
BindingContext = new ChamberButtonViewModel(); |
|
19 |
InitializeComponent(); |
|
47 |
vm.UpdateChamberId(id); |
|
20 | 48 |
} |
21 |
|
|
22 |
private static void OnChamberIdChanged(BindableObject bindable, object oldValue, object newValue) |
|
49 |
} |
|
50 |
private static void OnTimerChanged(BindableObject bindable, object oldValue, object newValue) |
|
51 |
{ |
|
52 |
if (bindable is ChamberButtonView view) |
|
23 | 53 |
{ |
24 |
var control = (ChamberButtonView)bindable; |
|
25 |
|
|
26 |
if (control.BindingContext is ChamberButtonViewModel viewModel) |
|
27 |
{ |
|
28 |
viewModel.UpdateProperties((int)newValue); |
|
29 |
} |
|
54 |
view.OnBindingContextChanged(); |
|
30 | 55 |
} |
31 | 56 |
} |
57 |
|
|
32 | 58 |
} |
Formats disponibles : Unified diff