Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By default Menus don't support this, but by little modifications, you can easily implement this behavior.</p> <p>For example:</p> <pre><code>public class AutoHideMenuItem : MenuItem { DispatcherTimer timer; private Int32 _autoHideDelay; public Int32 AutoHideDelay { get { return _autoHideDelay; } set { _autoHideDelay = value; timer.Interval = TimeSpan.FromSeconds(AutoHideDelay); } } public AutoHideMenuItem() { MouseMove += new MouseEventHandler(AutoHideMenuItem_MouseMove); ContextMenuOpening += new ContextMenuEventHandler(AutoHideMenuItem_ContextMenuOpening); SubmenuClosed += new RoutedEventHandler(AutoHideMenuItem_SubmenuClosed); timer = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher); timer.Interval = TimeSpan.FromSeconds(AutoHideDelay); timer.Stop(); timer.Tick += new EventHandler(timer_Tick); } void timer_Tick(object sender, EventArgs e) { if (IsSubmenuOpen &amp;&amp; !IsMouseOver) { IsSubmenuOpen = false; } } void AutoHideMenuItem_MouseMove(object sender, MouseEventArgs e) { timer.Stop(); timer.Start(); } void AutoHideMenuItem_ContextMenuOpening(object sender, ContextMenuEventArgs e) { timer.Start(); } void AutoHideMenuItem_SubmenuClosed(object sender, RoutedEventArgs e) { timer.Stop(); } } </code></pre> <p>Can be used like:</p> <pre><code> &lt;local:AutoHideMenuItem Header="File" AutoHideDelay="3"&gt; &lt;MenuItem Header="New"&gt;&lt;/MenuItem&gt; &lt;MenuItem Header="Open"&gt;&lt;/MenuItem&gt; &lt;MenuItem Header="Close"&gt;&lt;/MenuItem&gt; &lt;MenuItem Header="Exit"&gt;&lt;/MenuItem&gt; &lt;/local:AutoHideMenuItem&gt; </code></pre> <p>Which will close this menu after 3 seconds. Of course its rough code and you will need to make changes to it to suit your scenario.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload