Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0 VS2010
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
Edited 28-Sep-12 14:32pm
103K
v3
Comments
joshrduncan2012 at 28-Sep-12 17:19pm
   
Can you provide some of your code where you think the problem is occurring?
BillWoodruff at 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 at 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 at 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 at 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 at 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
0 OriginalGriff 371
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 PhilLenoir 70
4 Pheonyx 50
0 Sergey Alexandrovich Kryukov 6,676
1 OriginalGriff 6,056
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2014
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