ContextMenu cm; TextBlock tb; private void BuildTB() { cm = new ContextMenu(); cm.Background = new SolidColorBrush(Colors.Black); MenuItem menuItem = new MenuItem() { Header = "Edit", Foreground = new SolidColorBrush(Colors.White), Background = new SolidColorBrush(Colors.Black) }; menuItem.Click += EditItem_Click; cm.Items.Add(menuItem); tb = new TextBlock(); tb.Text = "My text block"; tb.Hold += OpenCM; ContextMenuService.SetContextMenu(tb, cm); } private void OpenCM(object sender, System.Windows.Input.GestureEventArgs e) { TextBlock tb = (TextBlock)sender; ContextMenu cm = ContextMenuService.GetContextMenu(tb); cm.IsOpen = true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)