Skip to content

Instantly share code, notes, and snippets.

@EdCharbeneau
Last active January 27, 2020 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdCharbeneau/ec48cdc1049ee916cbefecf9052b0c1d to your computer and use it in GitHub Desktop.
Save EdCharbeneau/ec48cdc1049ee916cbefecf9052b0c1d to your computer and use it in GitHub Desktop.
Cancelable Event
void HandleTabChange(TabEventArgs args)
{
var value = (Foo)args.Value;
if (value.Id == 1)
{
args.Cancel = true;
}
else
{
SelectedItem = value;
}
}
public class TabEventArgs
{
public object Value { get; set; }
public bool Cancel { get; set; }
}
/// <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