This question is locked. New answers and comments are not allowed.
Hi,
I have a RadMenu like this:
And a command in the viewmodel like this:
When I click on the New menu item, it opens the message box but it leaves the menu open (see attached screenshot). The menu only closes when I click OK in the message box.
The same is true if I change the MessageBox.Show line to Thread.Sleep(3000) - the menu remains open until 3 seconds have elapsed.
Instead I want the menu to close before the command is invoked. How can I do this?
Many thanks
Ed
I have a RadMenu like this:
<
telerik:RadMenu
>
<
telerik:RadMenuItem
Header
=
"File"
>
<
telerik:RadMenuItem
Header
=
"New"
Command
=
"{Binding Path=NewCommand}"
/>
</
telerik:RadMenuItem
>
</
telerik:RadMenu
>
And a command in the viewmodel like this:
NewCommand =
new
DelegateCommand(
delegate
()
{
MessageBox.Show(
"This is a test"
,
"Message"
, MessageBoxButton.OK);
});
When I click on the New menu item, it opens the message box but it leaves the menu open (see attached screenshot). The menu only closes when I click OK in the message box.
The same is true if I change the MessageBox.Show line to Thread.Sleep(3000) - the menu remains open until 3 seconds have elapsed.
Instead I want the menu to close before the command is invoked. How can I do this?
Many thanks
Ed
5 Answers, 1 is accepted
0
Lancelot
Top achievements
Rank 1
answered on 04 Jun 2012, 07:17 PM
Hi Ed,
I have seen this issue before and I know the Telerik team is working on a solution. I have found and example for you that might close the menu at the time you want it to.
Use this method in the event handler where you want the menu to close, it is a workaround that causes the menu to collapse.
Let em know if this didnt work for you and we'll dig in deeper.
Good Luck!
Lancelot
I have seen this issue before and I know the Telerik team is working on a solution. I have found and example for you that might close the menu at the time you want it to.
Use this method in the event handler where you want the menu to close, it is a workaround that causes the menu to collapse.
RadMenuItemAutomationPeer CloseME = new RadMenuItemAutomationPeer(menuItemRoot);
CloseME
.Invoke();
Let em know if this didnt work for you and we'll dig in deeper.
Good Luck!
Lancelot
0
Ed
Top achievements
Rank 1
answered on 11 Jun 2012, 10:57 AM
Hi Lancelot,
Thanks for looking into this for me. However, it turns out that this code essentially re-clicks the menu item rather than closing the menu.
Can Telerik confirm that this is a known issue or provide a workaround?
Many thanks
Ed
Thanks for looking into this for me. However, it turns out that this code essentially re-clicks the menu item rather than closing the menu.
Can Telerik confirm that this is a known issue or provide a workaround?
Many thanks
Ed
0
Lancelot
Top achievements
Rank 1
answered on 11 Jun 2012, 04:10 PM
Hi Ed,
When you call for MessageBox.Show, it blocks the calling thread, so the UI won't update.
Use the dispatcher to change the thread you are using for the messagebox. This should solve the problem of the the menu not closing.
Call the MessageBox like this:
Good Luck,
Lancelot
When you call for MessageBox.Show, it blocks the calling thread, so the UI won't update.
Use the dispatcher to change the thread you are using for the messagebox. This should solve the problem of the the menu not closing.
Call the MessageBox like this:
Dispatcher.BeginInvoke(() => MessageBox.Show(“This is a test”));
Good Luck,
Lancelot
0
Ed
Top achievements
Rank 1
answered on 14 Jun 2012, 09:59 AM
Hi Lancelot,
Thanks for the big clue! It turned out that just wrapping the call with Dispatcher.Invoke still had the same problem. I had to spawn a new thread and start it with a Thread.Sleep to allow the menu to close, as follows:
This seems to work - hope there aren't any unintended consequences when I invoke a longer method with more points of user interaction.
It would still be good to hear from Telerik as to whether there is another way. The 30ms sleep time was chosen arbitrarily.
Many thanks
Ed
Thanks for the big clue! It turned out that just wrapping the call with Dispatcher.Invoke still had the same problem. I had to spawn a new thread and start it with a Thread.Sleep to allow the menu to close, as follows:
public
MyViewModel()
{
NewCommand =
new
DelegateCommand(
delegate
()
{
Thread thread =
new
Thread(
new
ThreadStart(
delegate
()
{
Thread.Sleep(30);
Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(
"This is a test"
));
}));
thread.IsBackground =
true
;
thread.Start();
});
}
This seems to work - hope there aren't any unintended consequences when I invoke a longer method with more points of user interaction.
It would still be good to hear from Telerik as to whether there is another way. The 30ms sleep time was chosen arbitrarily.
Many thanks
Ed
0
Hi Ed,
George
the Telerik team
You could use only the Dispatcher without running the code in a new thread - it should do the trick. Please, refer to the attachment where you can find a sample project with a video.
Hope this helps.
George
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>