Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
added users to drop down menu tab
Browse files Browse the repository at this point in the history
  • Loading branch information
lsobtafo committed Mar 6, 2024
1 parent 4a21d11 commit ba0d364
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,87 @@ public MainWindowViewModel()
/// This method will edit the Query and fill out the field with the desired query and you can edit the query
/// </summary>
/// <param name="sender">This is the object that is clicked when executing</param>



/// New code begins here

private void LoadCustomQueries()
{
try
{
// Assuming Get-Users returns a list of users
List<User> users = GetUsersCommand(); // Replace this with your actual PowerShell command

foreach (User user in users)
{
// Create a new button for each user
Button newUserButton = new() { Height = 48 };

// Set button content (text) to user's name or any relevant information
newUserButton.Content = user.UserName;

// Bind the user object to the button
newUserButton.Tag = user;

// Create a context menu for the button
ContextMenu contextMenu = new ContextMenu();

// Add menu items to the context menu
MenuItem menuItem1 = new MenuItem { Header = "Execute" };
menuItem1.Command = ExecuteCommandButton;
menuItem1.CommandParameter = newUserButton;

MenuItem menuItem2 = new MenuItem { Header = "Edit" };
menuItem2.Command = EditCustomQuery;
menuItem2.CommandParameter = newUserButton;

MenuItem menuItem3 = new MenuItem { Header = "Delete" };
menuItem3.Command = Remove_ParameterComboBox;

// Add menu items to the context menu
contextMenu.Items.Add(menuItem1);
contextMenu.Items.Add(menuItem2);
contextMenu.Items.Add(menuItem3);

// Set the context menu for the button
newUserButton.ContextMenu = contextMenu;

// Add the button to the stack panel
ButtonStackPanel.Add(newUserButton);
}
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
}

// Replace User with your actual user class
public class User
{
public string UserName { get; set; }
// Add other properties as needed
}

// Replace this with your actual PowerShell command to get users
private List<User> GetUsersCommand()
{
// Your PowerShell command logic to get users
return new List<User>
{
new User { UserName = "User1" },
new User { UserName = "User2" },

};
}

/// New code ends here <summary>



/// </summary>
/// <param name="sender"></param>
private void EditCustomQuery(object sender)
{
// Get the button that we are editing
Expand Down

0 comments on commit ba0d364

Please sign in to comment.