Statistiques
| Branche: | Révision:

root / GES_PAC / View / Controls / ChamberButtonView.xaml.cs @ e837cdf1

Historique | Voir | Annoter | Télécharger (1,737 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 12ddf7ef lbihannic
        }
39 e837cdf1 lbihannic
    }
40
    private static void OnChamberIdChanged(BindableObject bindable, object oldValue, object newValue)
41
    {
42
        var control = (ChamberButtonView)bindable;
43
        int id = (int)newValue;
44 12ddf7ef lbihannic
45 e837cdf1 lbihannic
        if (control.BindingContext is ChamberButtonViewModel vm)
46 12ddf7ef lbihannic
        {
47 e837cdf1 lbihannic
            vm.UpdateChamberId(id);
48 12ddf7ef lbihannic
        }
49 e837cdf1 lbihannic
    }
50
    private static void OnTimerChanged(BindableObject bindable, object oldValue, object newValue)
51
    {
52
        if (bindable is ChamberButtonView view)
53 12ddf7ef lbihannic
        {
54 e837cdf1 lbihannic
            view.OnBindingContextChanged();
55 12ddf7ef lbihannic
        }
56
    }
57 e837cdf1 lbihannic
58 12ddf7ef lbihannic
}