Last active
January 27, 2020 22:58
-
-
Save EdCharbeneau/ec48cdc1049ee916cbefecf9052b0c1d to your computer and use it in GitHub Desktop.
Cancelable Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void HandleTabChange(TabEventArgs args) | |
{ | |
var value = (Foo)args.Value; | |
if (value.Id == 1) | |
{ | |
args.Cancel = true; | |
} | |
else | |
{ | |
SelectedItem = value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TabEventArgs | |
{ | |
public object Value { get; set; } | |
public bool Cancel { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sets the active Tab | |
/// </summary> | |
/// <param name="tab"></param> | |
public void SetActiveTab(ITab tab) | |
{ | |
if (ActiveTab != tab) | |
{ | |
var args = new TabEventArgs { Value = tab.Value }; | |
OnChange.InvokeAsync(args); | |
if (!args.Cancel) | |
{ | |
ActiveTab = tab; | |
StateHasChanged(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment