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

Commit

Permalink
Bound combobox drop down and selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
lsobtafo committed Mar 13, 2024
1 parent e818467 commit 7074de8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
7 changes: 4 additions & 3 deletions ActiveDirectoryQuerier/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@
<!-- TODO: Pieter: Bind button to another property inside the MainWindowViewModel -->
<Button Content="Execute" HorizontalAlignment="Left" Margin="368,43,0,0"
VerticalAlignment="Top" Height="23" Width="95" />
<!-- TODO: Pieter: Bind combobox to another property for the SelectedItem and ItemsSource, inside the MainWindowViewModel -->
<ComboBox HorizontalAlignment="Left" Margin="31,44,0,0" VerticalAlignment="Top"
Width="207"
Height="26" />
Width="207" Height="26"
SelectedItem="{Binding SelectedCommandFromComboBoxInActiveDirectoryInfo}"
ItemsSource="{Binding AvailableOptionsFromComboBoxInActiveDirectoryInfo}" />
</Grid>
<!-- TODO: Pieter: Bind this to a property in the MainWindowViewModel -->
<TextBox Grid.Row="1" Text="{Binding ConsoleOutputInActiveDirectoryInfo.ConsoleOutput}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="10" IsReadOnly="True" TextWrapping="Wrap"
Expand Down
46 changes: 24 additions & 22 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged
private AppConsole _consoleOutputInQueryBuilder;
private AppConsole _consoleOutputInActiveDirectoryInfo;
private Command? _selectedCommandFromComboBoxInQueryBuilder;
private Command? _selectedCommandFromComboBoxInActiveDirectoryInfo;
private ObservableCollection<Button>? _buttons; // TODO: Rename to be more descriptive.

// [[ Other fields ]] ----------------------------------------------------------- //
Expand Down Expand Up @@ -59,6 +60,7 @@ public AppConsole ConsoleOutputInQueryBuilder
}
}

// TODO: Pieter: Use this for the console output in the Active Directory Info tab (link in GUI)
public AppConsole ConsoleOutputInActiveDirectoryInfo
{
get => _consoleOutputInActiveDirectoryInfo;
Expand Down Expand Up @@ -106,6 +108,26 @@ public Command? SelectedCommandFromComboBoxInQueryBuilder
}
}
}

public Command? SelectedCommandFromComboBoxInActiveDirectoryInfo
{
get => _selectedCommandFromComboBoxInActiveDirectoryInfo;
set
{
if (_selectedCommandFromComboBoxInActiveDirectoryInfo != value)
{
_selectedCommandFromComboBoxInActiveDirectoryInfo = value;
OnPropertyChanged(nameof(SelectedCommandFromComboBoxInActiveDirectoryInfo));
}
}
}

public List<string> AvailableOptionsFromComboBoxInActiveDirectoryInfo { get; } = new()
{
"Get user on domain",
"Get computers on domain",
"Get IP of each system on domain"
};

public ObservableCollection<Button> QueryButtonStackPanel => _buttons ??= new ObservableCollection<Button>();

Expand Down Expand Up @@ -143,7 +165,7 @@ public Command? SelectedCommandFromComboBoxInQueryBuilder
public ICommand ImportQueryFileRelay { get; }
public ICommand ClearConsoleOutputInActiveDirectoryInfoRelay {
get;
} // TODO: Pieter use this for clear console button
} // TODO: Impliment functionality.....

/* TODO: for Pieter
*
Expand All @@ -154,28 +176,8 @@ public ICommand ClearConsoleOutputInActiveDirectoryInfoRelay {
* Create a property to act as the relay to the execution button.
*/


//NEW CODE
// Property for ComboBox dropdown options/text
public ObservableCollection<string> ActiveDirectoryCommandsList { get; private set; }

// Property to contain the selected item
private string _selectedComboBoxCommand;
public string SelectedComboBoxCommand
{
get => _selectedComboBoxCommand;
set
{
if (_selectedComboBoxCommand != value)
{
_selectedComboBoxCommand = value;
OnPropertyChanged(nameof(SelectedComboBoxCommand));
}
}
}

// Property to act as the relay to the execution button
public ICommand ExecuteCommandRelay { get; }
//NEW CODE
// [ Constructor ] ------------------------------------------------------------- //

public MainWindowViewModel()
Expand Down

0 comments on commit 7074de8

Please sign in to comment.