Forum Xamarin.Forms

Javascript funcionality in C# and xamarin

MihaelMihael Member ✭✭

Example of code in javascript:

function OnChangeEvent(){

if (_btnChange !== null) {
                window.clearTimeout(_btnChange ); //cancel the previous timer.
                _btnChange = null;
}
 _btnChange = window.setTimeout(function () { commitChanges(item); }, 3000);

}

function commitChanges(item){
window.clearTimeout(_btnChange );
_btnChange = null;

//Actual code that needs to execute is here

}

Explanation what this code does:
I have 3 (or more, doesnt matter) buttons and on click event is called OnChangeEvent function. This code ensure that when i click on one button it starts timer of 3 seconds and if inside that period of 3 seconds user clicks on different button that time resets and so on. With this i make sure the last clicked button gets executed.

And this control is much more like selection group buttons then real buttons.
How to do this in C# and xaml. I tried using system.Timers.Timer and tried with cancellation task but did not make it work. There should be something simpler.

Best Answers

Answers

Sign In or Register to comment.