:: Home

  login:         
  passwords:  

WPF FAQs

WPF General Questions
Concepts Element Tree
Concepts Dependency Property
Concepts Attached Property
Concepts Routed Events
Concepts Resources.
Concepts Animation
Concepts Freezable Object
Concepts Input and Commands.
Concepts Layouts
XAML Inline Styles and Templates
XAML XML Namespaces
XAML Code Behind
XAML Custom Class
XAML Type Converters
Content Model ItemControl
Content Model HeaderedItemsControl
Content Model HeaderedContentControl
Content Model Content Control
Content Model Decorator Content Model
Content Model Panel Content Model
Documents Serialization and Storage
Documents Annotations
Documents Flow Content
Documents Printing
Graphics and Multimedia Rendering Graphics
Graphics and Multimedia Animation and Timing
Graphics and Multimedia 2D Graphics
Graphics and Multimedia 3D Graphics
Graphics and Multimedia Visual Layer
Control Customization Adorners
Control Customization Stylable controls
Control Customization ControlTemplates
Data Data Binding
Data DragandDrop
Data Serialization
Globalization and Localization Attributes
Globalization and Localization Comments
Globalization and Localization Globalization Struc
Application and Deployment ClickOnce
Application and Deployment Frame
Application and Deployment Page
Application and Deployment Navigation
Application and Deployment Setup
Application and Deployment Window
Interoperability Message Loops Between
Interoperability Win32 in WPF
Interoperability WPF in Win32
Interoperability Windows Forms and WPF
Security Trusted Security
Security Partial Trust Security
Tools Microsoft Expression Blend
Tools ZAM3D
Tools XAMLPAD
Controls ToolTip
Controls TextBlock
Controls TabControl
Controls ProgressBar
Controls PrintDialog
Controls Popup
Controls TextBox
Controls Canvas
Controls ComboBox
Controls ListBox
Controls StatusBar
Controls ToolBar
Controls Context Menu
Controls Expander
Controls DocumentViewer
Controls FlowDocumentReader
Controls GroupBox
Controls GridSplitter
Controls Image
Controls Menu
Controls ScrollBar
Controls Slider
Controls RichTextBox
Controls Border
Controls Buttons

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

Winforms Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Controls Context Menu Interview Questions & FAQs

Questions and answers for Controls Context Menu.

67. Controls Context Menu

    67.1 How do I make the Context Menu appear only when clicked at certain portions of the Control ?
    67.2 How can I enable a Context Menu on a disabled Control ?
    67.3 How can I create a shared Context Menu ?
    67.4 How do I make the Context Menu to close after a set time interval?

67.1 How do I make the Context Menu appear only when clicked at certain portions of the Control ?

You can listen to the Popup event, determine where the mouse was clicked and selectively make the menu items visible in the menu as follows.

[C#]

private void contextMenu1_Popup(object sender, EventArgs e)
{
// Get current mouse click position in the control
// (assuming pictureBox1 is the control):
Point ptClick = pictureBox1.PointToClient(Control.MousePosition);

// Get the rectangle where you want to show the context menu.
Rectangle preferredClickRect = new Rectangle(0, 0, 50, 50);
if (preferredClickRect.Contains(ptClick))
{
// Show all the menu items so that the menu will appear
foreach (MenuItem item in contextMenu1.MenuItems)
item.Visible = true;
}

else
{
// Hide all the menu items so that the menu will not appear
foreach (MenuItem item in contextMenu1.MenuItems)
item.Visible = false;
}
}

67.2 How can I enable a Context Menu on a disabled Control ?

This example uses the ContextMenuService to display a Context Menu for a button that is disabled.

[XAML]

<Button Height="30" Content="Disabled Button" IsEnabled="False"

ContextMenuService.ShowOnDisabled="True">

<Button.ContextMenu>

<ContextMenu>

<MenuItem Header="Item 1"/>

<MenuItem Header="Item 2"/>

<MenuItem Header="Item 3"/>

</ContextMenu>

</Button.ContextMenu>

</Button>


67.3 How can I create a shared Context Menu ?

One common way of moving the focus around in a user interface on Windows is to use the Tab key to move sequentially between the controls. The contents of a WPF toolbar seems to act like a kind of tabbing black-hole. The focus goes in there but never comes out again. Try pasting this XAML code into the XAMLPad to see the problem.

[XAML]

<DockPanel>

<ToolBar DockPanel.Dock="Top">

<Button Content="B"

     Command="EditingCommands.ToggleBold" />

<Button Content="U"

     Command="EditingCommands.ToggleUnderline" />

<Button Content="I"

     Command="EditingCommands.ToggleItalic" />

</ToolBar>

<RichTextBox />

</DockPanel>

Fortunately this can be easily fixed by using the "KeyboardNavigation" attached property and changing the TabNavigation to 'Continue'. This allows the tab focus to move out of the toolbar and back to the other elements of the UI.

[XAML]

<DockPanel>

<ToolBar DockPanel.Dock="Top"

      KeyboardNavigation.TabNavigation="Continue">

<Button Content="B"

     Command="EditingCommands.ToggleBold" />

<Button Content="U"

     Command="EditingCommands.ToggleUnderline" />

<Button Content="I"

     Command="EditingCommands.ToggleItalic" />

</ToolBar>

<RichTextBox />

</DockPanel>


67.4 How do I make the Context Menu to close after a set time interval?

To automatically close the context menu after a set time interval, you can use a Timer and send an Esc keystroke after the desired time interval as shown.

[C#]

private void timer1_Tick(object sender, System.EventArgs e)
{
SendKeys.Send("{ESC}");
timer1.Stop();
}

private void contextMenu1_Popup(object sender, System.EventArgs e)
{
//set interval to 5 seconds
timer1.Interval = 5000;
timer1.Start();
}

bottom user control
::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd