private void item_Click(object sender, RoutedEventArgs e) { int index = FindIndex(sender); if (index != -1) { if (index == this.MenuItems.Length - 2) { var window = new NewCategoryWindow(); window.Owner = App.Current.MainWindow; window.ValidateName = new Func <string, string>(delegate(string name) { if (String.IsNullOrWhiteSpace(name)) { return("Please pick a name"); } if (this._Categoies == null) { return(null); } for (int i = 0; i < this._Categoies.Length; i++) { if (this._Categoies[i].Name == name) { return("The name \"" + name + "\" already exists!"); } } return(null); }); if (window.ShowDialog() == true) { Pages.ViewRunsPage.Category newCat = window.Category; // Create a new category here! var cs = this.NewCategory; if (cs != null) { cs(newCat); } cs = this.CategorySelected; if (cs != null) { cs(newCat); } } } else if (index == this.MenuItems.Length - 1) { var cs = this.CategorySelected; if (cs != null) { cs(null); } } else { var cs = this.CategorySelected; if (cs != null) { cs(this.Categoies[index]); } } } }
private void item_Click(object sender, RoutedEventArgs e) { int index = FindIndex( sender ); if ( index != -1 ) { if ( index == this.MenuItems.Length - 2 ) { var window = new NewCategoryWindow(); window.Owner = App.Current.MainWindow; window.ValidateName = new Func<string, string>( delegate(string name) { if ( String.IsNullOrWhiteSpace( name ) ) return "Please pick a name"; if ( this._Categoies == null ) return null; for ( int i = 0; i < this._Categoies.Length; i++ ) { if ( this._Categoies[i].Name == name ) { return "The name \"" + name + "\" already exists!"; } } return null; } ); if ( window.ShowDialog() == true ) { Pages.ViewRunsPage.Category newCat = window.Category; // Create a new category here! var cs = this.NewCategory; if ( cs != null ) { cs( newCat ); } cs = this.CategorySelected; if ( cs != null ) { cs( newCat ); } } } else if ( index == this.MenuItems.Length - 1 ) { var cs = this.CategorySelected; if ( cs != null ) { cs( null ); } } else { var cs = this.CategorySelected; if ( cs != null ) { cs( this.Categoies[index] ); } } } }