I have a XAML MainWindow and Child User control loaded on that window. On button click event in user control I disable mainWindow as Well as User Control till a work on button click is not finished. When I again updating the property from User control to enable the window again, now user control keys are not working, because while debugging its showing IsEnabled Property of window/user control is still disable. I am also forcefully updating user control property this.IsEnabled = true; but still its not updating IsEnabled property of class true. How could I update the mainwindow and user control property to enable or how could my Control keys can work again.
Asked
Active
Viewed 97 times
0
-
Try to [set focus](https://stackoverflow.com/q/23316274/1997232) after enabling it. – Sinatr Mar 16 '18 at 12:11
-
@Sinatr thanks for reply, but focus is not working for me – Praveen sharma Mar 16 '18 at 13:08
1 Answers
1
If you set mainWindow.IsEnabled to false, you cannot set userControl.IsEnabled to true. You have to set the mainWindow.IsEnabled to true first. You cannot have an enabled control inside a disabled control.
I wrote a simple WPF app with a user control with a button. The main window has the user control and the code for the user control is:
public partial class MyUserControl : UserControl
{
DispatcherTimer m_timer = new DispatcherTimer();
public MyUserControl()
{
InitializeComponent();
m_timer.Tick += Timer_Tick;
m_timer.Interval = TimeSpan.FromSeconds(4);
}
private void Timer_Tick(object sender, EventArgs e)
{
Window window = Window.GetWindow(this);
window.IsEnabled = true;
m_timer.Stop();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Window window = Window.GetWindow(this);
window.IsEnabled = false;
m_timer.Start();
}
}

Sean Halliday
- 46
- 4
-
Thanks for your reply, its main window is enabled already but i don't know why user control is not enabling. – Praveen sharma Mar 16 '18 at 16:20
-
You will have to post some code. Also try Snoop (https://github.com/cplotts/snoopwpf) and try manually inspecting and setting IsEnabled in it in the visual tree. – Sean Halliday Mar 16 '18 at 16:40