/// <summary> /// 执行按钮Click事件 /// </summary> /// <param name="sender"></param> public static void PerformClick(this System.Windows.Controls.Primitives.ButtonBase sender) { //System.Windows.Automation.Peers.ButtonAutomationPeer bam = new System.Windows.Automation.Peers.ButtonAutomationPeer(button); //System.Windows.Automation.Provider.IInvokeProvider iip = bam.GetPattern(System.Windows.Automation.Peers.PatternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider; //iip.Invoke(); sender.RaiseEvent(System.Windows.Controls.Primitives.ButtonBase.ClickEvent); }
private void Button(System.Windows.Controls.Primitives.ButtonBase c) { bool toggle = c is CheckBox; var n = c.Name; WriteBoolField(n, ((toggle && ((CheckBox)c).IsChecked.Value) ? true : false), c.ClipToBounds); WriteLine("bool old" + n + " = " + n + ";"); WriteLine(n + " = GUI." + (toggle ? "Toggle" : "Button") + "(" + Rect(c) + (toggle ? "," + n : "") + ", new GUIContent(" + GetContent(c.Content) + ",\"" + c.Tag + "\"));"); WriteLine("if (" + n + " != old" + n + (toggle ? "" : " && " + n) + " ) {" + Action(n) + "onButtonClick(); }"); WriteLine("onMouseOver = " + Rect(c) + ".Contains(Event.current.mousePosition);"); WriteLine("if (oldMouseOver" + n + " != onMouseOver && onMouseOver) onOver();"); WriteLine("oldMouseOver" + n + " = onMouseOver;"); WritePrivateField("bool oldMouseOver" + n + ";"); }
protected override void OnDetaching() { base.OnDetaching(); if (this.AssociatedObject != null) { System.Windows.Controls.Primitives.ButtonBase button = this.AssociatedObject as System.Windows.Controls.Primitives.ButtonBase; if (button != null) { button.Click -= AssociatedObject_Click; } else { this.AssociatedObject.MouseLeftButtonUp -= AssociatedObject_MouseLeftButtonUp; } } }
/// <summary> /// Called when the control's Template is expanded. /// </summary> public override void OnApplyTemplate() { // Unhook from old template if (null != _valueButtonPart) { _valueButtonPart.Click -= OnValueButtonClick; } base.OnApplyTemplate(); // Hook up to new template _valueButtonPart = GetTemplateChild(ButtonPartName) as System.Windows.Controls.Primitives.ButtonBase; if (null != _valueButtonPart) { _valueButtonPart.Click += OnValueButtonClick; } }
virtual public void ini(ref int row, ref int col) //初始化并添加到父窗体中 { if (cmddes.repeat_T > 0) //若是重复指令 { tb = new System.Windows.Controls.Primitives.ToggleButton(); } else //若是单次触发指令 { tb = new Button(); tb.Click += new RoutedEventHandler((RoutedEventHandler) delegate(object sender, RoutedEventArgs e) { send_cmd(); }); } tb.Content = cmddes.name; tb.Tag = cmddes.name; tb.Margin = bt_margin; add_ctrl(tb, ref row, ref col); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); this.UpButton = GetTemplateChild(PART_UpButton) as System.Windows.Controls.Primitives.ButtonBase; this.DownButton = GetTemplateChild(PART_DownButton) as System.Windows.Controls.Primitives.ButtonBase; }
void HandleElement(System.Windows.Controls.Primitives.ButtonBase baseButton) { MessageBox.Show(baseButton.Content + " is clicked"); }
void AssociatedObject_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { MapContents cont = ControlTreeHelper.FindAncestorOfType <MapContents>(AssociatedObject); if (cont == null) { return; } MapContentsConfiguration conf = cont.DataContext as MapContentsConfiguration; if (conf == null) { return; } if (ToolPanels.Current != null && !string.IsNullOrWhiteSpace(conf.ContextMenuToolPanelName)) { _toolPanel = ToolPanels.Current[conf.ContextMenuToolPanelName]; } if (_toolPanel == null) { return; } _contextMenu = new ContextMenu(); if (ContextMenuStyle != null) { _contextMenu.Style = ContextMenuStyle; } // Bind background and foreground properties to context menu Binding b = new Binding("ContextMenuBackground") { Source = this }; _contextMenu.SetBinding(ContextMenu.BackgroundProperty, b); b = new Binding("ContextMenuForeground") { Source = this }; _contextMenu.SetBinding(ContextMenu.ForegroundProperty, b); // set the control to the current culture settings (LTR/RTL) RTLHelper helper = System.Windows.Application.Current.Resources["RTLHelper"] as RTLHelper; Debug.Assert(helper != null); if (helper != null) { _contextMenu.FlowDirection = helper.FlowDirection; } foreach (FrameworkElement button in _toolPanel.ToolPanelItems) { System.Windows.Controls.Primitives.ButtonBase btnBase = button as System.Windows.Controls.Primitives.ButtonBase; if (btnBase != null) { MenuItem item = new MenuItem(); ButtonDisplayInfo info = btnBase.DataContext as ButtonDisplayInfo; if (info != null) { item.Header = info.Label; if (!string.IsNullOrEmpty(info.Icon)) { Image image = new Image(); Binding binding = new Binding("Icon") { Converter = _urlResolver }; image.SetBinding(Image.SourceProperty, binding); image.DataContext = info; item.Icon = image; } item.Command = btnBase.Command; _contextMenu.Items.Add(item); } } else { _contextMenu.Items.Add(new Separator()); } } Point point = e.GetPosition(null); if (point != null) { _contextMenu.HorizontalOffset = point.X; _contextMenu.VerticalOffset = point.Y; } LayerItemViewModel layerViewModel = AssociatedObject.DataContext as LayerItemViewModel; if (layerViewModel != null && layerViewModel.Layer != null) { if (!CoreExtensions.GetIsSelected(layerViewModel.Layer)) { SetSelectedLayer(layerViewModel.Layer); } } if (_contextMenu.Items.Count > 0) { _contextMenu.IsOpen = true; if (_contextMenu.FlowDirection == FlowDirection.RightToLeft) { // Now that the popup is open, we can update the layout measurements so that // the ActualWidth is available. _contextMenu.UpdateLayout(); _contextMenu.HorizontalOffset -= _contextMenu.ActualWidth; } } }
public void ClickButton(System.Windows.Controls.Primitives.ButtonBase button) { this.Dispatcher.Invoke((Action)(() => button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)) )); }
protected ButtonBaseAutomationPeer(System.Windows.Controls.Primitives.ButtonBase owner) : base(default(System.Windows.FrameworkElement)) { }