MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Windows;5using System.Windows.Controls;6 7namespace Microsoft.PowerShell.Commands.ShowCommandInternal8{9 /// <summary>10 /// Interaction logic for CmdletControl.xaml.11 /// </summary>12 public partial class CmdletControl : UserControl13 {14 /// <summary>15 /// Field used for the CurrentCommandViewModel parameter.16 /// </summary>17 private CommandViewModel currentCommandViewModel;18 19 #region Construction and Destructor20 /// <summary>21 /// Initializes a new instance of the CmdletControl class.22 /// </summary>23 public CmdletControl()24 {25 InitializeComponent();26 this.NotImportedControl.ImportModuleButton.Click += ImportModuleButton_Click;27 this.ParameterSetTabControl.DataContextChanged += new DependencyPropertyChangedEventHandler(this.ParameterSetTabControl_DataContextChanged);28 this.KeyDown += this.CmdletControl_KeyDown;29 this.helpButton.innerButton.Click += this.HelpButton_Click;30 }31 #endregion32 33 #region Properties34 /// <summary>35 /// Gets the owner of the ViewModel.36 /// </summary>37 private CommandViewModel CurrentCommandViewModel38 {39 get { return this.currentCommandViewModel; }40 }41 #endregion42 43 #region Private Events44 45 /// <summary>46 /// DataContextChanged event.47 /// </summary>48 /// <param name="sender">Event sender.</param>49 /// <param name="e">Event args.</param>50 private void ParameterSetTabControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)51 {52 if (this.DataContext == null)53 {54 return;55 }56 57 CommandViewModel viewModel = (CommandViewModel)this.DataContext;58 this.currentCommandViewModel = viewModel;59 60 if (viewModel.ParameterSets.Count == 0)61 {62 return;63 }64 65 this.ParameterSetTabControl.SelectedItem = viewModel.ParameterSets[0];66 }67 68 /// <summary>69 /// Key down event for user press F1 button.70 /// </summary>71 /// <param name="sender">Event sender.</param>72 /// <param name="e">Event args.</param>73 private void CmdletControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)74 {75 if (e.Key == System.Windows.Input.Key.F1)76 {77 this.CurrentCommandViewModel.OpenHelpWindow();78 }79 }80 81 /// <summary>82 /// Help button event.83 /// </summary>84 /// <param name="sender">Event sender.</param>85 /// <param name="e">Event args.</param>86 private void HelpButton_Click(object sender, RoutedEventArgs e)87 {88 this.CurrentCommandViewModel.OpenHelpWindow();89 }90 91 /// <summary>92 /// Import Module Button event.93 /// </summary>94 /// <param name="sender">Event sender.</param>95 /// <param name="e">Event args.</param>96 private void ImportModuleButton_Click(object sender, RoutedEventArgs e)97 {98 this.CurrentCommandViewModel.OnImportModule();99 }100 #endregion101 }102}103 