本文整理汇总了C#中System.Windows.Controls.ContextMenu.AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu.AddHandler方法的具体用法?C# ContextMenu.AddHandler怎么用?C# ContextMenu.AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContextMenu
的用法示例。
在下文中一共展示了ContextMenu.AddHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopupContextMenu
public PopupContextMenu()
{
Title = "Popup Context Menu";
//ContextMenu 생성
menu = new ContextMenu();
//"Bold" 항목 추가
itemBold = new MenuItem();
itemBold.Header = "Bold";
menu.Items.Add(itemBold);
//"Italic" 항목 추가
itemItalic = new MenuItem();
itemItalic.Header = "Italic";
menu.Items.Add(itemItalic);
//모든 TextDecorationLocation 멤버를 구함
TextDecorationLocation[] locs=(TextDecorationLocation[])Enum.GetValues(typeof (TextDecorationLocation));
//MenuItem 객체 배열을 생성를 구함
itemDecor=new MenuItem[locs.Length];
for (int i = 0; i < locs.Length; i++)
{
TextDecoration decor = new TextDecoration();
decor.Location = locs[i];
itemDecor[i] = new MenuItem();
itemDecor[i].Header = locs[i].ToString();
itemDecor[i].Tag = decor;
menu.Items.Add(itemDecor[i]);
}
//전체 컨텍스트 메뉴를 핸들러 한 개로 처리
menu.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuOnClick));
//윈도우 Content 를 위한 TextBlock을 생성
TextBlock text = new TextBlock();
text.FontSize = 32;
text.HorizontalAlignment = HorizontalAlignment.Center;
text.VerticalAlignment = VerticalAlignment.Center;
Content = text;
//문장을 단어로 분리
string strQuote = "To be,or not to be,that is the question";
string[] strWords = strQuote.Split();
//각 단어로 Run 객체를 만들어서 TextBlock에 추가
foreach (string str in strWords)
{
Run run = new Run(str);
//TextDecorations이 실제로 컬렉션인지를 확인
run.TextDecorations = new TextDecorationCollection();
text.Inlines.Add(run);
text.Inlines.Add(" ");
}
}
示例2: createSelectionCanvasMenu
/// <summary>
/// Creates the selection canvas context menu
/// </summary>
private void createSelectionCanvasMenu()
{
cmSelectionCanvas = new ContextMenu();
MenuItem miZoom25 = new MenuItem();
miZoom25.Header = "Zoom 25%";
miZoom25.Tag = "0.25";
MenuItem miZoom50 = new MenuItem();
miZoom50.Header = "Zoom 50%";
miZoom50.Tag = "0.5";
MenuItem miZoom100 = new MenuItem();
miZoom100.Header = "Zoom 100%";
miZoom100.Tag = "1.0";
cmSelectionCanvas.Items.Add(miZoom25);
cmSelectionCanvas.Items.Add(miZoom50);
cmSelectionCanvas.Items.Add(miZoom100);
cmSelectionCanvasRoutedEventHandler = new RoutedEventHandler(MenuSelectionCanvasOnClick);
cmSelectionCanvas.AddHandler(MenuItem.ClickEvent, cmSelectionCanvasRoutedEventHandler);
selectCanvForImg.ContextMenu = cmSelectionCanvas;
}
示例3: createDragCanvasMenu
/// <summary>
/// Creates the drag canvas context menu
/// </summary>
private void createDragCanvasMenu()
{
cmSelectionCanvas.RemoveHandler(MenuItem.ClickEvent, cmSelectionCanvasRoutedEventHandler);
selectCanvForImg.ContextMenu = null;
cmSelectionCanvas = null;
cmDragCanvas = new ContextMenu();
MenuItem miCancel = new MenuItem();
miCancel.Header = "Cancel";
MenuItem miSave = new MenuItem();
miSave.Header = "Save";
cmDragCanvas.Items.Add(miCancel);
cmDragCanvas.Items.Add(miSave);
cmDragCanvasRoutedEventHandler = new RoutedEventHandler(MenuDragCanvasOnClick);
cmDragCanvas.AddHandler(MenuItem.ClickEvent, cmDragCanvasRoutedEventHandler);
dragCanvasForImg.ContextMenu = cmDragCanvas;
}