root / GES_PAC / View / Controls / ChamberButtonView.xaml.cs @ 42456640
Historique | Voir | Annoter | Télécharger (1,771 ko)
1 | e837cdf1 | lbihannic | using GES_PAC.ViewModel; |
---|---|---|---|
2 | using GES_PAC.ViewModel.Controls; |
||
3 | 12ddf7ef | lbihannic | |
4 | e837cdf1 | lbihannic | namespace GES_PAC.View.Controls; |
5 | |||
6 | public partial class ChamberButtonView : ContentView |
||
7 | 12ddf7ef | lbihannic | { |
8 | e837cdf1 | lbihannic | 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() |
||
31 | 12ddf7ef | lbihannic | { |
32 | e837cdf1 | lbihannic | base.OnBindingContextChanged(); |
33 | 12ddf7ef | lbihannic | |
34 | e837cdf1 | lbihannic | if (BindingContext is not ChamberButtonViewModel && ChamberId != 0 && Timer != null) |
35 | 12ddf7ef | lbihannic | { |
36 | e837cdf1 | lbihannic | var vm = new ChamberButtonViewModel(ChamberId, Timer); |
37 | BindingContext = vm; |
||
38 | 42456640 | lbihannic | vm.UpdateProperties(); |
39 | 12ddf7ef | lbihannic | } |
40 | e837cdf1 | lbihannic | } |
41 | private static void OnChamberIdChanged(BindableObject bindable, object oldValue, object newValue) |
||
42 | { |
||
43 | var control = (ChamberButtonView)bindable; |
||
44 | int id = (int)newValue; |
||
45 | 12ddf7ef | lbihannic | |
46 | e837cdf1 | lbihannic | if (control.BindingContext is ChamberButtonViewModel vm) |
47 | 12ddf7ef | lbihannic | { |
48 | e837cdf1 | lbihannic | vm.UpdateChamberId(id); |
49 | 12ddf7ef | lbihannic | } |
50 | e837cdf1 | lbihannic | } |
51 | private static void OnTimerChanged(BindableObject bindable, object oldValue, object newValue) |
||
52 | { |
||
53 | if (bindable is ChamberButtonView view) |
||
54 | 12ddf7ef | lbihannic | { |
55 | e837cdf1 | lbihannic | view.OnBindingContextChanged(); |
56 | 12ddf7ef | lbihannic | } |
57 | } |
||
58 | e837cdf1 | lbihannic | |
59 | 12ddf7ef | lbihannic | } |