views:

251

answers:

3

Hi! I have an WPF application that has a main window. In the left side of this Window there are some buttons into a listbox, it is a kind of menu to access faster to pages. These buttons belongs to pages that they are loaded inside the window when the user selects one.

Main window also has another main menu in the top for doing other tasks.

When a page is loaded in the main window and the user clicks a button of this currently loaded page, it starts a task that takes a long time. While this long task is executing I want the user can not select (or press) any of the buttons into the listbox because In the loaded page the long task also is updating the UI for this page. I would like to disabled (isEnabled=false) the listbox when long task is executing and not to enabled it until the long task has finished. How can I do this? I mean, from the page is currently loaded I want to disabled the listbox placed in the main window that is the owner.

The listbox doesn't belong to the currently loaded page.

Thanks!

A: 
Steve Psaltis
A: 

Thanks for your help but I haven't worked with ICommands yet and It is a little difficult for me to understand. I would appreciate If you could post here a very little example on how can I implement it.

For example, in my main window 'WinMain' I have a listbox 'MyLstBox' with some buttons and I want from another page 'MyPage' that contains a button 'btnDoLongTask' to set MyLstBox.isEnabled = false. How can I implement something like this?

Sorry... but I have no idea about ICommands despite reading some documents... and an example always is the best to understand it.

Thanks in advance.

toni
A: 

Hey!

Finally I have learnt about how to do with Icommand. After spending a lot of time, I saw what powerful it was and I bound all my clickable controls in what I was interested to re-enabled/disabled to commands and the commands with canBeExecute return false when long tasks (background workers) is in progress. I have implemented a command static class to check if one of the background workers (long tasks) is running and into it one method that return true or false depending on whether one task is running. So in canExecuted method I check this accessing the method placed into the class.

Thanks for your good idea!

i'm glad i could be of service ! Please vote for my answer if you liked it.
Steve Psaltis