Click here to Skip to main content
12,452,066 members (64,157 online)
Rate this:
 
Please Sign up or sign in to vote.
hi guys ,
I have a User Control Contains a Toolbar , the Tool bar Contains 3 Buttons With routed Command i put the user Control in a Windows form when i click any where on the control All buttons Disabled suddenly when i click again in text box or any control writable or selectable it's enabled once again how can i solve this problem
#region Add
        private void CanExecuteAdd(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
 
            e.Handled = true;
        }
 
        private void AddExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            this.ClearControls();
        }
        #endregion
        #region Close
        private void CanExecuteClose(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
 
        private void CloseExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                if (this.IsChanged())
                {
                    string ST = "هل ترغب فى حفظ التعديلات  ؟";
                    MessageBoxResult R = MessageBox.Show(ST, "حفظ", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
                    if (R == MessageBoxResult.Yes)
                    {
                        this.Maintain_CloseForm_Med();
                    }
                    else
                    {
                        this.Close();
                    }
                }
                else
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

private void IntializeRoutedCommand()
        {
            //==========OpenRoutedCommand Of ToolBar================
            RoutedUICommand NewRoutedCommand = new RoutedUICommand();
            CommandBinding NewCommandBinding = new CommandBinding(NewRoutedCommand, AddExecuted, CanExecuteAdd);
            NewRoutedCommand.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control));
            this.CommandBindings.Add(NewCommandBinding);
            this.Btn_New.Command = NewRoutedCommand;
            //=======================================================
            RoutedUICommand ClearRoutedCommand = new RoutedUICommand();
            CommandBinding ClearCommandBinding = new CommandBinding(ClearRoutedCommand, ClearExecuted, CanExecuteAdd);
            ClearRoutedCommand.InputGestures.Add(new KeyGesture(Key.R, ModifierKeys.Control));
            this.CommandBindings.Add(ClearCommandBinding);
            this.Btn_Clear.Command = ClearRoutedCommand;
            //=======================================================}
Posted 28-Sep-12 10:48am
Updated 28-Sep-12 14:32pm
v3
Comments
joshrduncan2012 28-Sep-12 17:19pm
   
Can you provide some of your code where you think the problem is occurring?
BillWoodruff 28-Sep-12 19:47pm
   
You need to clarify what you mean by "its button Disabled."

UserControl losing focus when you click outside the UserControl is standard behavior.

By saying "button disabled" you are implying the Button changes appearance to indicate it will not receive clicks.

Are you, anywhere in your code, handling a LostFocus type of event for the UserControl or the Button in it and changing its 'Enabled property ?

good luck, Bill
yayaNasr 28-Sep-12 21:22pm
   
hi Bill , it is Routed Command and buttons Disabled when i click any where in the User control, that is my problem
yayaNasr 28-Sep-12 21:20pm
   
it is Routed Command and buttons Disabled when i click any where in the User control that is my problem
BillWoodruff 29-Sep-12 1:28am
   
When you click again on the UserControl, after it has lost focus by your clicking on the Window: does the Button become 'Enabled again ?
yayaNasr 29-Sep-12 17:42pm
   
yes , when i click in any control can write in it like text box
it re-enabled

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100