Saturday, February 14, 2015

How to create a context menu with LinsUIWPF Suite

Download   Demonstration  Question?   Contact Us

1.     Follow the link How to create a new project to create your project with LinsUIWPF Suite.
2.     Highlight “MyDemo” project folder, and Project->New Folder to create a new folder named “Icons”.
3.     Project->Add Existing Item …, and select icons to add them into the “Icons” folder.
4.     Project->Add New Item …, it should bring up the following dialog.

Choose “WPF” as Category and “User Control (WPF)” as Template. Use “MyContextMenu” as the class name. Click “Add” button.
5.     Open MyContextMenu.xaml. Change the following code,
<UserControl x:Class="MyDemo.MyContextMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
           
</Grid>
</UserControl>
to as follows, and assign an unique ID to it. The unique ID is for layout persistent. It should be between 1,000 and 10,000,000.
<src:ContextMenuDropDown x:Class="MyDemo.MyContextMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:src="clr-namespace:LinsUIWPF;assembly=LinsUIWPF"
Height="300" Width="300" ID="1021">
<Grid>
            
</Grid>
</src:ContextMenuDropDown>
6.     Open MyContextMenu.xaml.cs.
Add the following line,
      using LinsUIWPF;
and change the following code,
public partial class MyContextMenu : UserControl
{
public MyContextMenu()
{
InitializeComponent();
}
}
to as follows,
public partial class MyContextMenu ContextMenuDropDown
{
public MyContextMenu()
{
InitializeComponent();
}
}
7.     Close MyContextMenu.xaml, then reopen it again, the screen should show the following,
8.     Click the combo box; it will pop up the list,
9.     Select “Add a menuitem”, and then click and select the new created menu item,
10.  Go to Properties panel.  Choose an icon, and enter for “Text”, “ToolTipText”, and “HelpContext”. Assign a unique ID to it
11.  Click the combo box; it will pop up the list, select “Add a menuitem”
12.  Repeat step 8 and 9.
13.  Continue to add items
14.  Open Window1.xaml.cs.
Add the following code, and assign the context menu to some object.
public partial class Window1 : LinsMDIWindow
{
public Window1()
{
InitializeComponent();
  
MyPanel panel = new MyPanel();
panel.ShowPanel();

FlexContextMenu contextMenu = new FlexContextMenu();
contextMenu.DropDownMenu = new MyContextMenu();
panel.ContextMenu = contextMenu;
}
}



References:
Command,
Command Events,
Commands Manager,
Context Menu,
Features,
How To,
Index,
Instruction,
LinsUIWPFDockingManager,
Tool Items Manager

No comments:

Post a Comment