private void KeyVaultTreeControl_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (e.NewValue != null) { var selected = (TreeViewItem)e.NewValue; if (selected.DataContext is KeyVault) { VaultSelected?.Invoke(this, (KeyVault)selected.DataContext); } if (selected.DataContext is KeyVaultSecret) { SecretSelected?.Invoke(this, (KeyVaultSecret)selected.DataContext); } if (selected.DataContext is KeyVaultKey) { KeySelected?.Invoke(this, (KeyVaultKey)selected.DataContext); } } }