0

I'm trying to create an event handler, that when some button is tapped on Content Dialog, the main Page or the Page that has called the Content Dialog receive the event.

I have found some examples about it in Stackoverflow as in other forums, but the one I'm using to get what I've told is this one. I'm having some problemas to create the event raiser and because it's my first time trying to do something like that I'm a bit lost on the implementation.

This is my code:

someClass.cs

public class updatedDB 
{

        public enum updateType
        {
            Delete, Update, None
        }


        private updateType _updateType;
        private bool _isUpdated;
        private int _ID;

        private bool IsUpdated
        {
            get { return _isUpdated; }
            set
            {
                _isUpdated = value;
                ValueChanged?.Invoke(value);
            }
        }

        public void NotifyUpdate(int ID, updateType UpdateType)
        {
            if (UpdateType == updateType.None)
                return;
            else
            {
                IsUpdated   = true;
                _ID         = ID;
                _updateType = UpdateType;
            }

        }


        public updateType GetUpdateType()
        {
            return _updateType;
        }

        public int GetUpdatedID()
        {
            return _ID;
        }

        public event ValueChangedEventHandler ValueChanged;
    }

    public delegate void ValueChangedEventHandler(bool value);

And this is the event handler in another .cs file (Page.cs):

    public Page()
    {
        this.InitializeComponent();

        HardwareButtons.BackPressed += HardwareButtons_BackPressed;

        UpdateEvent.ValueChanged += UpdateSpots;
    }

    private ValueChangedEventHandler UpdateSpots(bool value)
    {
        ValueChangedEventHandler handler = new ValueChangedEventHandler(value);
        return handler;
    }

Currently I have two part of this code underlined in red and I don't know how to correct them:

UpdateEvent.ValueChanged += **UpdateSpots**;

UpdateSpots is giving me "has an incorrect type of value " (translated to english from my VS GUI language).

And,

ValueChangedEventHandler handler = new ValueChangedEventHandler(**value**);

value is giving me "waiting name of method" error.

Thank you in advance.

  • 1
    The signature of the method subscribing to the event must match the event handler one. If you type only `UpdateEvent.ValueChanged +=` and hit TAB twice it will create the method for you. Visual Studio rocks. – Cleptus Mar 17 '20 at 11:54
  • Thank you! Now it seems that easy... It works! – Imanol Zubiaurre Mar 17 '20 at 16:37

0 Answers0