locked
Cannot find the static member on the type RRS feed

  • Question

  • 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

    Monday, September 16, 2013 5:32 PM

Answers

  • Hi,

    According to your description and code, it seems the CommandBinding was the issue.

    <CommandBinding Command="{x:Static view:uclMainWindow.ShowMaintainDisksWindow}"
                        CanExecute="CanExecuteDisplayMaintainDisksWindow"
                        Executed="DisplayMaintainDisksWindow" />

    We should create a RoutedCommand which is defining the command and instantiating it from Code-Behind in ViewModel:

    public static RoutedCommand ShowMaintainDisksWindow = new RoutedCommand();

    Please check the following references:

    #How to: Create a RoutedCommand
    http://msdn.microsoft.com/en-us/library/ms752070.aspx

    #Executing Command Logic in a View Model
    http://www.codeproject.com/Articles/101881/Executing-Command-Logic-in-a-View-Model


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by lynnosler Tuesday, September 17, 2013 12:25 PM
    Tuesday, September 17, 2013 8:38 AM

All replies

  • Hi,

    According to your description and code, it seems the CommandBinding was the issue.

    <CommandBinding Command="{x:Static view:uclMainWindow.ShowMaintainDisksWindow}"
                        CanExecute="CanExecuteDisplayMaintainDisksWindow"
                        Executed="DisplayMaintainDisksWindow" />

    We should create a RoutedCommand which is defining the command and instantiating it from Code-Behind in ViewModel:

    public static RoutedCommand ShowMaintainDisksWindow = new RoutedCommand();

    Please check the following references:

    #How to: Create a RoutedCommand
    http://msdn.microsoft.com/en-us/library/ms752070.aspx

    #Executing Command Logic in a View Model
    http://www.codeproject.com/Articles/101881/Executing-Command-Logic-in-a-View-Model


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by lynnosler Tuesday, September 17, 2013 12:25 PM
    Tuesday, September 17, 2013 8:38 AM
  • Yes, that is what I had forgotten.  Thank you! 
    Tuesday, September 17, 2013 12:25 PM