WPF MenuItem hiding

D

Dmitry Nogin

Hi,

I would like to hide selected MenuItem on <Delete> key press without closing the menu.

My markup is:


<Menu>

<MenuItem Header="Menu">

<MenuItem Header="First" KeyDown="MenuItem_KeyDown"/>

<MenuItem Header="Second" KeyDown="MenuItem_KeyDown"/>

<MenuItem Header="Third" KeyDown="MenuItem_KeyDown"/>

</MenuItem>

</Menu>

where event handler is:

private void MenuItem_KeyDown(object sender, KeyEventArgs e)

{

if (e.Key == Key.Delete)

{

MenuItem mi = (MenuItem)sender;

mi.Visibility = Visibility.Collapsed;

}

}



Unfortunately, I can not hide currently highlighted MenuItem without the whole menu collapse.



The question is how to bypass this misbehavior? How to change menu selection before hiding?





P.S. Which newsgroup should use I to ask WPF related questions?





Thanks,

-- Dmitry
 
J

James VanDyne

Describe the intended behavior a little more...

Would you want the menu item just before the one that's currently active to be selected? There are some boundary conditions that may get you around to what you're after. For example: unselect the sender, select the menu just at IndexOfSender - 1, then hide your sender.

Does that make sense?

--
James VanDyne, MCPD
Technical Consultant
Hi,

I would like to hide selected MenuItem on <Delete> key press without closing the menu.

My markup is:


<Menu>

<MenuItem Header="Menu">

<MenuItem Header="First" KeyDown="MenuItem_KeyDown"/>

<MenuItem Header="Second" KeyDown="MenuItem_KeyDown"/>

<MenuItem Header="Third" KeyDown="MenuItem_KeyDown"/>

</MenuItem>

</Menu>

where event handler is:

private void MenuItem_KeyDown(object sender, KeyEventArgs e)

{

if (e.Key == Key.Delete)

{

MenuItem mi = (MenuItem)sender;

mi.Visibility = Visibility.Collapsed;

}

}



Unfortunately, I can not hide currently highlighted MenuItem without the whole menu collapse.



The question is how to bypass this misbehavior? How to change menu selection before hiding?





P.S. Which newsgroup should use I to ask WPF related questions?





Thanks,

-- Dmitry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top