Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using Metronome.Shared;
- using Xamarin.Forms;
- namespace MyProject.Views
- {
- public partial class MainPage : ContentPage
- {
- public MainPage()
- {
- InitializeComponent();
- }
- protected override void OnPropertyChanging([CallerMemberName] string propertyName = null)
- {
- base.OnPropertyChanging(propertyName);
- if (propertyName == nameof(BindingContext) && BindingContext is IFlashlight flashlight)
- SetEventHandler(false);
- }
- protected override void OnBindingContextChanged()
- {
- base.OnBindingContextChanged();
- SetEventHandler(true);
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- SetEventHandler(true);
- }
- protected override void OnDisappearing()
- {
- SetEventHandler(false);
- base.OnDisappearing();
- }
- bool isAttached;
- void SetEventHandler(bool attach)
- {
- if (isAttached == attach) return;
- if (BindingContext is IFlashlight flashlight)
- {
- if (attach)
- flashlight.Flash += OnFlash;
- else
- flashlight.Flash -= OnFlash;
- }
- isAttached = attach;
- }
- private void OnFlash(bool obj)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement