I have an application with external windows. This application is complete, I am just revising it. I have hit a snag and can't figure out why it is different when I copy/paste code and change the references and such.
I have a drop down menu item "Maintain Disks" with the Command Binding.
Am I missing something?
<CommandBinding Command="{x:Static view:uclMainWindow.ShowMaintainDisksWindow}" CanExecute="CanExecuteDisplayMaintainDisksWindow" Executed="DisplayMaintainDisksWindow" /><MenuItem Header="Maintain Disks..." Visibility="{Binding IsCurrentUserAdministrator, Converter={local:BooleanToVisibilityConverter}}" Command="{x:Static view:uclMainWindow.ShowMaintainDisksWindow}" />
Xaml ^
/// <summary> /// Converts a boolean value to the appropriate Visibility setting. /// </summary> public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter { private static BooleanToVisibilityConverter _converter = null; /// <summary> /// Supplies a value to XAML /// </summary> /// <param name="serviceProvider"></param> /// <returns>an instance of the converter class /// </returns> public override object ProvideValue(IServiceProvider serviceProvider) { if (_converter == null) _converter = new BooleanToVisibilityConverter(); return _converter; } #region IValueConverter Members /// <summary> /// Converts a boolean value to the appropriate Visibility setting. /// </summary> /// <returns>Visible if the supplied boolean value is true. Collapsed if false. (Returns the opposite value if /// the supplied parameter is not null.)</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null && (bool)value == true) { return (parameter == null) ? Visibility.Visible : Visibility.Collapsed; } else return (parameter == null) ? Visibility.Collapsed : Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } #endregion }Converter ^
/// <summary> /// Call the Disks Maintenance Window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DisplayMaintainDisksWindow(object sender, ExecutedRoutedEventArgs e) { try { ViewModelMainWindow dataContext = (ViewModelMainWindow)this.DataContext; dataContext.DisplayMaintainDisksWindow(); } catch (Exception ex) { App.DisplayErrorMessage(null, null, ex); } } /// <summary> /// Determines whether the Diagnostics menu option is available. /// </summary> ///<param name="sender">a reference to the control that triggered the event</param> /// <param name="e">the arguments associated with the CanExecute event</param> private void CanExecuteDisplayMaintainDisksWindow(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; }
Code Behind
public void DisplayMaintainDisksWindow() { LoaderService.ShowChildWindow(new ViewModelMaintainDisks()); }View Model