Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
#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
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
Yasser El Shazly 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
Yasser El Shazly 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 ?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900