Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - A Brief Look at Menus in WPF
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

A Brief Look at Menus in WPF
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-09-22

    Table of Contents:
  • A Brief Look at Menus in WPF
  • More on MenuItem
  • Handling Input
  • Context Menus

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Brief Look at Menus in WPF - More on MenuItem


    (Page 2 of 4 )

    In some situations, more functionality is needed for menu items. In certain situations, some menu items may need to be disabled. For example, consider a context menu for a standard text box, containing Copy, Cut and Paste menu items. If no text is highlighted, then it doesn't make sense for the user to be able to copy or cut anything. So, it makes sense for those options to be disabled.

    Whether or not a menu item is enabled is determined by the value of IsEnabled. You can set IsEnabled to false in order to disable a menu item. For example, below, the Copy and Cut menu items would be disabled:


    <MenuItem Header="Copy" IsEnabled="False" />

    <MenuItem Header="Cut" IsEnabled="False" />

    <MenuItem Header="Paste" />


    Another useful bit of functionality is a check box of sorts on a menu item. Some menu items can be made to turn a feature on or off. If the feature is on, a check mark will be placed to the left of the menu item's text. If the feature is off, then the check mark will not appear.

    This functionality is easy to implement. It involves two properties: IsCheckable and IsChecked. The IsCheckable property determines whether or not the item can be checked, and the IsChecked property determines whether or not the item actually is checked. The default value for IsChecked is false, so creating a checkable menu item without setting IsChecked will result in an unchecked menu item.

    Below, we create a menu item that can be checked:


    <MenuItem Header="Syntax Highlighting" IsCheckable="True" />


    And here, we create a menu item that is checked by default:


    <MenuItem Header="Standard Mode" IsCheckable="True"

     IsChecked="True" />


    In order to make menus more accessible, it's a good idea to provide access keys for menu items. This will not only make keyboard-loving users happy, but it will allow people with various disabilities to use your application. The presence of an access key is indicated by an underlined letter in an item's label. The item can be "clicked" by pressing Alt and the underlined letter.

    Access keys are very easy to implement. The process is the same as with any other control. When specifying the MenuItem's Header, simply add an underscore before the desired access key character. For example, with a File menu, an access key might be set up like this:


    <MenuItem Header="_File">

    ...

    </MenuItem>


    Pressing the Alt key will show the F as being underlined, and then pressing the F key will activate the File menu.

    More Windows Scripting Articles
    More By Peyton McCullough


       · Hey, all,Menus are obviously a huge part of many applications. In this article,...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek