/// <summary> /// Remove a user defined property /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnRemove_Click(object sender, RoutedEventArgs e) { int idx = lbProperties.SelectedIndex; if (this.CheckProjectIsEditable(false)) { UserDefinedProperty p = lbProperties.SelectedItem as UserDefinedProperty; if (p != null) { if (p.UnderlyingProperty != null) { this.Project.MSBuildProject.RemoveProperty(p.UnderlyingProperty); } userDefinedProperties.Remove(p); if (idx >= lbProperties.Items.Count) { idx--; } if (idx >= 0) { lbProperties.SelectedIndex = idx; } } } }
/// <summary> /// This is used to add a new user-defined property to the project /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnAdd_Click(object sender, RoutedEventArgs e) { if (this.CheckProjectIsEditable(false)) { UserDefinedProperty newProp = new UserDefinedProperty(this, null); this.UserDefinedProperties.Add(newProp); lbProperties.SelectedIndex = lbProperties.Items.Count - 1; } }
/// <summary> /// This is used to load the user-defined properties from the project /// </summary> public void LoadUserDefinedProperties() { UserDefinedProperty propItem; lbProperties.ItemsSource = null; try { isLoading = true; foreach (ProjectProperty prop in this.Project.UserDefinedProperties.OrderBy(p => p.Name)) { propItem = new UserDefinedProperty(this, prop); userDefinedProperties.Add(propItem); } } catch (Exception ex) { MessageBox.Show("Unable to load user-defined properties. Error " + ex.Message, Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } finally { isLoading = false; lbProperties.ItemsSource = userDefinedProperties; } if (lbProperties.Items.Count == 0) { pgProps.IsEnabled = btnRemove.IsEnabled = false; } else { lbProperties.SelectedIndex = 0; } }