private void RowDefinition_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var window = (Window)((FrameworkElement)sender).TemplatedParent; ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["MacWindowTemplate"]; Button RestoreButton = (Button)baseWindowTemplate.FindName("RestoreButton", window); Button maxBtn = (Button)baseWindowTemplate.FindName("MaxBtn", window); if (e.ClickCount == 2) { if (window.ResizeMode == ResizeMode.NoResize) { } else if (window.WindowState == WindowState.Maximized) { window.WindowState = WindowState.Normal; maxBtn.Visibility = Visibility.Visible; RestoreButton.Visibility = Visibility.Collapsed; } else if (window.WindowState == WindowState.Normal) { window.WindowState = WindowState.Maximized; maxBtn.Visibility = Visibility.Collapsed; RestoreButton.Visibility = Visibility.Visible; } } }
protected virtual void DialogueLoaded(object sender, EventArgs args) { ControlTemplate ct = (ControlTemplate)Application.Current.Resources["LunalipseDialogueBaseTemplate"]; (ct.FindName("TitleBar", this) as Border).MouseDown += TitleBarMove; (ct.FindName("BtnClose", this) as Ellipse).MouseDown += ClosePressed; }
private void InitializeEvent() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; Border borderTitle = (Border)baseWindowTemplate.FindName("borderTitle", this); Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this); Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this); YesButton = (Button)baseWindowTemplate.FindName("btnYes", this); NoButton = (Button)baseWindowTemplate.FindName("btnNo", this); minBtn.Click += delegate { MinWin(); }; closeBtn.Click += delegate { this.Close(); }; borderTitle.MouseMove += delegate(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { this.DragMove(); } }; }
public void InitEvent() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["baseWinTpl"]; Border borderTitle = (Border)baseWindowTemplate.FindName("borderTitle", this); Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this); Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this); Button maxBtn = (Button)baseWindowTemplate.FindName("btnMax", this); //TextBlock title = (TextBlock)baseWindowTemplate.FindName("Title", this); borderTitle.MouseMove += delegate(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { this.DragMove(); } }; closeBtn.Click += delegate { this.Close(); }; minBtn.Click += delegate { this.WindowState = WindowState.Minimized; }; maxBtn.Click += delegate { this.WindowState = WindowState.Maximized; }; }
void Bind() { ControlTemplate msgWindowTemplate = this.Template; // Image img = (Image)msgWindowTemplate.FindName("imgTitle", this); BitmapImage bitmap = new BitmapImage(new Uri(GetIconFile(), UriKind.RelativeOrAbsolute)); img.Source = bitmap; // TextBlock txt = (TextBlock)msgWindowTemplate.FindName("txtTitle", this); txt.Text = MsgTitle; // txt = (TextBlock)msgWindowTemplate.FindName("txtMsg", this); txt.Text = Msg; // Button btn = (Button)msgWindowTemplate.FindName("btnOK", this); btn.Click += (o, e) => { this.DialogResult = true; }; btn = (Button)msgWindowTemplate.FindName("btnCancel", this); btn.Click += (o, e) => { this.DialogResult = false; }; }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { ControlTemplate MainWindowTemplate = Application.Current.Resources["MainWindowTemplate"] as ControlTemplate; if (MainWindowTemplate != null) { CloseButton = MainWindowTemplate.FindName("CloseWinButton", this) as Button; MinButton = MainWindowTemplate.FindName("MinWinButton", this) as Button; MaxButton = MainWindowTemplate.FindName("MaxWinButton", this) as Button; CloseButton.Click += CloseButton_Click; MinButton.Click += MinButton_Click; MaxButton.Click += MaxButton_Click; WindowTitleTbl = MainWindowTemplate.FindName("WindowTitleTbl", this) as TextBlock; } //加载数据 Data.ReadData(); Data.ReadName(); InitLeftMusicListView(); //初始化左边的歌单名称列表 }
private void HideMargin() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; Grid MainGrid = (Grid)baseWindowTemplate.FindName("MainGrid", this); Grid ContentGrid = (Grid)baseWindowTemplate.FindName("ContentGrid", this); Border MainBorder = (Border)baseWindowTemplate.FindName("MainBorder", this); Border BorderTitle = (Border)baseWindowTemplate.FindName("BorderTitle", this); if (MainGrid == null) { return; } if (WinState == JvedioWindowState.Normal) { MainGrid.Margin = new Thickness(10); ContentGrid.Margin = new Thickness(5); this.ResizeMode = ResizeMode.CanResize; } else if (WinState == JvedioWindowState.Maximized || this.WindowState == WindowState.Maximized) { MainGrid.Margin = new Thickness(0); ContentGrid.Margin = new Thickness(0); this.ResizeMode = ResizeMode.NoResize; } }
private static void OnIsPositiveSequenceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DataGridExtend dg = GetCurrentGrid(d); List <DataGridColumnHeader> columnHeaders = GetVisualChildCollection <DataGridColumnHeader>(dg); foreach (var item in columnHeaders) { ControlTemplate ct = item.Template; Path pAscending = ct.FindName("pAscending", item) as Path; Path pDescending = ct.FindName("pDescending", item) as Path; pAscending.Visibility = Visibility.Collapsed; pDescending.Visibility = Visibility.Collapsed; } DataGridColumnHeader colHeader = GetCurrentSortColumn(d) as DataGridColumnHeader; ControlTemplate template = colHeader.Template; if ((bool)e.NewValue == true) { Path pAscending = template.FindName("pAscending", colHeader) as Path; pAscending.Visibility = Visibility.Visible; } else if ((bool)e.NewValue == false) { Path pDescending = template.FindName("pDescending", colHeader) as Path; pDescending.Visibility = Visibility.Visible; } }
private void InitEvent() { ControlTemplate baseDialogControlTemplate = (ControlTemplate)App.Current.Resources["BaseDialogControlTemplate"]; Button closeBtn = (Button)baseDialogControlTemplate.FindName("BorderClose", this); closeBtn.Click += delegate(object sender, RoutedEventArgs e) { FadeOut(); }; Button cancel = (Button)baseDialogControlTemplate.FindName("CancelButton", this); cancel.Click += delegate(object sender, RoutedEventArgs e) { this.DialogResult = false; }; Button confirm = (Button)baseDialogControlTemplate.FindName("ConfirmButton", this); confirm.Click += Confirm; Border borderTitle = (Border)baseDialogControlTemplate.FindName("BorderTitle", this); borderTitle.MouseMove += MoveWindow; FadeIn(); }
private void InitEvent() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; Button minBtn = (Button)baseWindowTemplate.FindName("BorderMin", this); minBtn.Click += delegate(object sender, RoutedEventArgs e) { MinWindow(); }; Button maxBtn = (Button)baseWindowTemplate.FindName("BorderMax", this); maxBtn.Click += MaxWindow; Button closeBtn = (Button)baseWindowTemplate.FindName("BorderClose", this); closeBtn.Click += delegate(object sender, RoutedEventArgs e) { FadeOut(); }; Border borderTitle = (Border)baseWindowTemplate.FindName("BorderTitle", this); borderTitle.MouseMove += MoveWindow; borderTitle.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { if (e.ClickCount >= 2) { MaxWindow(this, new RoutedEventArgs()); } }; this.SizeChanged += onSizeChanged; this.ContentRendered += delegate { HideMargin(); }; #region "改变窗体大小" //https://www.cnblogs.com/yang-fei/p/4737308.html Grid resizeGrid = (Grid)baseWindowTemplate.FindName("resizeGrid", this); if (resizeGrid != null) { foreach (UIElement element in resizeGrid.Children) { Rectangle resizeRectangle = element as Rectangle; if (resizeRectangle != null) { resizeRectangle.PreviewMouseDown += ResizeRectangle_PreviewMouseDown; resizeRectangle.MouseMove += ResizeRectangle_MouseMove; } } } PreviewMouseMove += OnPreviewMouseMove; #endregion FadeIn(); }
/// <summary> /// 初始化事件 /// </summary> private void InitializeEvent() { ControlTemplate template = (ControlTemplate)App.Current.Resources["DialogWindowTemplate"]; if (this.IsShowHelp) { Button btnHelp = (Button)template.FindName("btnHelp", this); btnHelp.Visibility = Visibility.Visible; btnHelp.Click += (s, e) => { //TODO 显示帮助信息 }; } Button btnMin = (Button)template.FindName("btnMin", this); btnMin.Click += (s, e) => { this.WindowState = WindowState.Minimized; }; Button btnClose = (Button)template.FindName("btnClose", this); btnClose.Click += (s, e) => { this.Close(); }; UniformGrid title = (UniformGrid)template.FindName("title", this); title.MouseMove += (s, e) => { if (e.LeftButton == MouseButtonState.Pressed) { this.DragMove(); } }; }
/// <summary> /// 窗体状态更改的时候的触发的事件, /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void MyMacClass_StateChanged(object sender, EventArgs e) { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["MacWindowTemplate"]; Button RestoreButton = (Button)baseWindowTemplate.FindName("RestoreButton", this); Button maxBtn = (Button)baseWindowTemplate.FindName("MaxBtn", this); Border borderClip = (Border)baseWindowTemplate.FindName("MacWindowFrame", this); Border borderCliptop = (Border)baseWindowTemplate.FindName("top", this); Border OutBorder = (Border)baseWindowTemplate.FindName("OutBorder", this); if (this.WindowState == WindowState.Maximized) { maxBtn.Visibility = Visibility.Collapsed; RestoreButton.Visibility = Visibility.Visible; CornerRadius corradius = new CornerRadius(0.0, 0.0, 0.0, 0.0); borderClip.CornerRadius = corradius; borderCliptop.CornerRadius = corradius; Thickness thick = new Thickness(0); OutBorder.BorderThickness = thick; } else if (this.WindowState == WindowState.Normal) { maxBtn.Visibility = Visibility.Visible; RestoreButton.Visibility = Visibility.Collapsed; CornerRadius corradius = new CornerRadius(10.0, 10.0, 0.0, 0.0); borderClip.CornerRadius = corradius; borderCliptop.CornerRadius = corradius; Thickness thick = new Thickness(30); OutBorder.BorderThickness = thick; } }
private void LoadMenu() { moduleMenu = (Menu)myTemplate.FindName("ModuleMenu", this); var modules = ModuleHelper.GetModuleInfo(); var menuitems = BuildMenu(modules); menuitems.ForEach(item => moduleMenu.Items.Add(item)); }
private void onSizeChanged(object sender, SizeChangedEventArgs e) { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; Grid MainGrid = (Grid)baseWindowTemplate.FindName("MainGrid", this); Grid ContentGrid = (Grid)baseWindowTemplate.FindName("ContentGrid", this); Border MainBorder = (Border)baseWindowTemplate.FindName("MainBorder", this); Border BorderTitle = (Border)baseWindowTemplate.FindName("BorderTitle", this); if (MainGrid == null) { return; } if (this.Width == SystemParameters.WorkArea.Width || this.Height == SystemParameters.WorkArea.Height) { MainGrid.Margin = new Thickness(0); ContentGrid.Margin = new Thickness(0); MainBorder.CornerRadius = new CornerRadius() { TopLeft = 0, TopRight = 0, BottomRight = 0, BottomLeft = 0 }; BorderTitle.CornerRadius = new CornerRadius() { TopLeft = 0, TopRight = 0, BottomRight = 0, BottomLeft = 0 }; this.ResizeMode = ResizeMode.NoResize; } else if (this.WindowState == WindowState.Maximized) { MainGrid.Margin = new Thickness(0); MainBorder.CornerRadius = new CornerRadius() { TopLeft = 0, TopRight = 0, BottomRight = 0, BottomLeft = 0 }; BorderTitle.CornerRadius = new CornerRadius() { TopLeft = 0, TopRight = 0, BottomRight = 0, BottomLeft = 0 }; this.ResizeMode = ResizeMode.NoResize; } else { MainGrid.Margin = new Thickness(10); ContentGrid.Margin = new Thickness(5); MainBorder.CornerRadius = new CornerRadius() { TopLeft = 5, TopRight = 5, BottomRight = 5, BottomLeft = 5 }; BorderTitle.CornerRadius = new CornerRadius() { TopLeft = 5, TopRight = 5, BottomRight = 0, BottomLeft = 0 }; this.ResizeMode = ResizeMode.CanResize; } }
private void InitializeEvent() { ControlTemplate baseWindowTemplate = (ControlTemplate)Application.Current.Resources["BaseWindowControlTemplate"]; minBtn = (Button)baseWindowTemplate.FindName("btnMin", this); if (isMin) { minBtn.Visibility = System.Windows.Visibility.Visible; } else { minBtn.Visibility = System.Windows.Visibility.Collapsed; } minBtn.Click += delegate { this.WindowState = WindowState.Minimized; }; maxBtn = (Button)baseWindowTemplate.FindName("btnMax", this); if (isMax) { maxBtn.Visibility = System.Windows.Visibility.Visible; } else { maxBtn.Visibility = System.Windows.Visibility.Collapsed; } maxBtn.Click += delegate { this.WindowState = (this.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal); }; Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this); closeBtn.Click += delegate { this.Close(); }; Border borderTitle = (Border)baseWindowTemplate.FindName("borderTitle", this); borderTitle.MouseMove += delegate(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { this.DragMove(); } }; borderTitle.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { if (e.ClickCount >= 2) { maxBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } }; }
public void Init(ProdClickHandler h, bool CanDelete) { this.phandler = h; this.wrapPanel1.Children.Clear(); PackerConfig pcfg = new PackerConfig(); foreach (string id in curr_packer.pkg_confs.Keys) { pcfg.FromElement(curr_packer.pkg_confs[id]); FileInfo fi; if (File.Exists(ProdNum.baseDir + "\\prodpic\\" + StringResource.language + "\\" + pcfg.product_desc + ".jpg")) { fi = new FileInfo(ProdNum.baseDir + "\\prodpic\\" + StringResource.language + "\\" + pcfg.product_desc + ".jpg"); } else { fi = new FileInfo(ProdNum.baseDir + "\\prodpic\\default.jpg"); } imglist[id] = fi.FullName; Label n = new Label(); ControlTemplate ct = this.FindResource("imgBtn") as ControlTemplate; n.Template = ct; n.Name = "ID" + id; //Product num: Pru n.Content = String.Format("{0}:{1}\n{2}:{3}\n{4}:{5}\n{6}:{7}\n{8}:{9}", StringResource.str("product_no"), pcfg.product_no, StringResource.str("product_desc"), pcfg.product_desc, StringResource.str("grp_target"), pcfg.target, StringResource.str("grp_uvar"), pcfg.upper_var, StringResource.str("grp_dvar"), pcfg.lower_var ); //n.Click += ImageSelected; n.ApplyTemplate(); Rectangle rectimg = ct.FindName("ImageRect", n) as Rectangle; rectimg.Name = "Rt" + id; Button delBtn = ct.FindName("DelBtn", n) as Button; delBtn.Name = "De" + id; rectimg.MouseLeftButtonUp += ImageRect_MouseLeftButtonUp; delBtn.Click += Delbtn_Click; if (!CanDelete) { delBtn.Visibility = Visibility.Hidden; } ImageBrush ib = ct.FindName("ImageFill", n) as ImageBrush; ib.ImageSource = new BitmapImage(new Uri(fi.FullName)); this.wrapPanel1.Children.Add(n); } this.Show(); }
/// <summary> /// 初始化,标题栏3个按钮的状态 /// </summary> private void InitutalizeStateVisable() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["MacWindowTemplate"]; Button RestoreButton = (Button)baseWindowTemplate.FindName("RestoreButton", this); Button maxBtn = (Button)baseWindowTemplate.FindName("MaxBtn", this); Button closeBtn = (Button)baseWindowTemplate.FindName("CloseBtn", this); Button minBtn = (Button)baseWindowTemplate.FindName("MinBtn", this); closeBtn.Visibility = Visibility.Visible; maxBtn.Visibility = Visibility.Collapsed; RestoreButton.Visibility = Visibility.Collapsed; minBtn.Visibility = Visibility.Collapsed; }
public UIImageControl() { InitializeComponent(); DragThumb.ApplyTemplate(); ControlTemplate template = DragThumb.Template; _imgMainImage = (Image)template.FindName("uiObjImage", DragThumb); _scrollviewer = (ScrollViewer)template.FindName("UIScrollViewer", DragThumb); RegisterEvents(); _imgMainImage.MouseDown += Image_MouseDown; _emSelectedState = emSelectedState.Selected; topleft = new Point(); bottomright = new Point(); }
private void InitutalizeStateVisable() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["MacWindowTemplate"]; Button RestoreButton = (Button)baseWindowTemplate.FindName("RestoreButton", this); Button maxBtn = (Button)baseWindowTemplate.FindName("MaxBtn", this); Button closeBtn = (Button)baseWindowTemplate.FindName("CloseBtn", this); Button minBtn = (Button)baseWindowTemplate.FindName("MinBtn", this); Border borderClip = (Border)baseWindowTemplate.FindName("MacWindowFrame", this); Border borderCliptop = (Border)baseWindowTemplate.FindName("top", this); Border OutBorder = (Border)baseWindowTemplate.FindName("OutBorder", this); Button SkinBtn = (Button)baseWindowTemplate.FindName("SkinBtn", this); SkinBtn.Visibility = Visibility.Visible; //根据状态 if (this.WindowState == WindowState.Maximized) { maxBtn.Visibility = Visibility.Collapsed; RestoreButton.Visibility = Visibility.Visible; CornerRadius corradius = new CornerRadius(0.0, 0.0, 0.0, 0.0); borderClip.CornerRadius = corradius; borderCliptop.CornerRadius = corradius; Thickness thick = new Thickness(0); OutBorder.BorderThickness = thick; } else if (this.WindowState == WindowState.Normal) { maxBtn.Visibility = Visibility.Visible; RestoreButton.Visibility = Visibility.Collapsed; CornerRadius corradius = new CornerRadius(10.0, 10.0, 0.0, 0.0); borderClip.CornerRadius = corradius; borderCliptop.CornerRadius = corradius; Thickness thick = new Thickness(30); OutBorder.BorderThickness = thick; } //根据resizeMode判断窗体窗台按钮的显示与隐藏 if (this.ResizeMode == ResizeMode.NoResize) { RestoreButton.Visibility = Visibility.Collapsed; maxBtn.Visibility = Visibility.Collapsed; minBtn.Visibility = Visibility.Collapsed; closeBtn.Visibility = Visibility.Visible; } else if (this.ResizeMode == ResizeMode.CanMinimize) { RestoreButton.Visibility = Visibility.Collapsed; maxBtn.Visibility = Visibility.Collapsed; minBtn.Visibility = Visibility.Visible; closeBtn.Visibility = Visibility.Visible; } else if (this.ResizeMode == ResizeMode.CanResizeWithGrip) { RestoreButton.Visibility = Visibility.Visible; maxBtn.Visibility = Visibility.Visible; minBtn.Visibility = Visibility.Visible; closeBtn.Visibility = Visibility.Visible; } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); ControlTemplate ct = this.Template; //Image lbl = ct.FindName("lblLeftMouseDown", this) as Image; //lbl.MouseLeftButtonDown += lbl_MouseLeftButtonDown; Button btn_Up = ct.FindName("btn_Up", this) as Button; Button btn_Down = ct.FindName("btn_Down", this) as Button; btn_Up.Click += btnUp_Click; btn_Down.Click += btnDown_Click; //this.TextChanged += WaterTextBoxSearchControl_TextChanged; this.KeyDown += WaterTextBoxSearchControl_KeyDown; this.Text = MinValue.ToString(); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); ControlTemplate template = this.Template; if (template != null) { TreeView tree = template.FindName("BodyText", this) as TreeView; if (tree != null) { tree.SizeChanged += new SizeChangedEventHandler(OnTreeSizeChanged); } mx = template.FindName("Boordje", this) as Border; } }
private void InitializeEvent() { ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; this.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual; Label laBel = (Label)baseWindowTemplate.FindName("lab_Title", this); laBel.Content = this.Title; Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this); minBtn.Click += delegate { this.WindowState = WindowState.Minimized; }; Button maxBtn = (Button)baseWindowTemplate.FindName("btnMax", this); maxBtn.Click += delegate { this.WindowState = (this.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal); }; Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this); closeBtn.Click += delegate { this.Close(); }; Border borderTitle = (Border)baseWindowTemplate.FindName("borderTitle", this); borderTitle.MouseMove += delegate(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { this.DragMove(); } }; borderTitle.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { if (e.ClickCount >= 2) { maxBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } }; }
/* LOAD OBJECTS */ private void WinFormsMaterialContextMenuItem_Loaded(object sender, RoutedEventArgs e) { switch (caseBool[1]) { case false: WinFormsMaterialContextMenuItem x = (WinFormsMaterialContextMenuItem)sender; th = this; temp = th.Template; MainGrid = (Grid)temp.FindName("MainGrid", th); border = (Border)MainGrid.FindName("Bd") as Border; iconContent = (Grid)MainGrid.FindName("iconContent") as Grid; iconContent.MouseLeftButtonUp += IconContent_MouseLeftButtonUp; gridContent = (Grid)MainGrid.FindName("gridContent") as Grid; headerContent = (Label)gridContent.FindName("headerContent") as Label; content = (TextBlock)gridContent.FindName("content") as TextBlock; headerText = headerContent.Content.ToString(); content.Text = headerText; rippleElement = (Ellipse)MainGrid.FindName("Ripple") as Ellipse; defaultBorderColor = colorConverter.convertToColor(border.Background); hoverBorderColor = colorConverter.convertToColor("#b9b9b9"); caseBool[1] = true; break; case true: caseBool[1] = false; break; } }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (pickerWindow != null) { pickerWindow.Hide(); } Win32.POINT p; if (!Win32.GetCursorPos(out p)) { return; } if (this.Left + RESIZE_BORDER < p.x && this.Left + this.ActualWidth - RESIZE_BORDER > p.x && this.Top + RESIZE_BORDER < p.y && this.Top + this.ActualHeight - RESIZE_BORDER > p.y) { this.DragMove(); } //双击最大化或还原 if (this.ResizeMode == ResizeMode.CanResize || this.ResizeMode == ResizeMode.CanResizeWithGrip) { ControlTemplate mainWindowTemplate = this.Template; Button maxBtn = (Button)mainWindowTemplate.FindName("btnMax", this); if (e.ClickCount >= 2) { maxBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } } base.OnMouseLeftButtonDown(e); }
/// <summary> /// 控件初始化 /// </summary> private void Initialize() { ControlTemplate baseWindowTemplate = this.Resources["settingTemplate"] as ControlTemplate; _closeButton = baseWindowTemplate.FindName("closeButton", this) as Button; _closeButton.Click += (sender, e) => this.Close(); }
public override void OnExecute(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { if (SelectionManager.SelectedShape != null) { if (SelectionManager.SelectedShape is Control) { Control ctrl = SelectionManager.SelectedShape as Control; ControlTemplate template = ctrl.Template; if (template != null) { TextBlock text = template.FindName("BodyText", ctrl) as TextBlock; if (text != null) { //doesn't make make much sense to accumulate the italic command in the undo stack... if (!text.FontStyle.Equals(FontStyles.Italic)) { //make it undoable MakeItalicCommand cmd = new MakeItalicCommand(text); UndoManager.Execute(cmd); } } } } } }
public ListBoxItemIndexRange(ListBox listBox) { ControlTemplate tmpl = listBox.Template as ControlTemplate; Viewer = tmpl.FindName("listBoxScrollViewer", listBox) as ScrollViewer; PartialMin = int.MaxValue; FullMin = int.MaxValue; FullMax = -1; PartialMax = -1; int n = listBox.Items.Count; for (int i = 0; i < n; i++) { ListBoxItem item = listBox.Items[i] as ListBoxItem; Point[] p = new Point[] { new Point(0, 0), new Point(item.ActualWidth + 1, item.ActualHeight + 1) }; p[0] = item.TranslatePoint(p[0], Viewer); p[1] = item.TranslatePoint(p[1], Viewer); if (Viewer.ActualHeight <= p[1].X) { Normalize(); return; } if (p[0].Y < Viewer.ActualHeight && 0 < p[1].Y) { PartialMin = Math.Min(PartialMin, i); PartialMax = i; } if (0 <= p[0].Y && p[1].Y < Viewer.ActualHeight) { FullMin = Math.Min(FullMin, i); FullMax = i; } } Normalize(); }
private void GetCanvasReference() { ControlTemplate scrollViewerControlTemplate = scrollViewer.Template; selectionRectangleCanvas = scrollViewerControlTemplate.FindName("SelectionRectangleCanvas", scrollViewer) as Canvas; selectionRectangleCanvas.RenderTransform = new TranslateTransform(); }
public void MaxWindow(object sender, RoutedEventArgs e) { if (WinState == JvedioWindowState.Normal) { //最大化 WinState = JvedioWindowState.Maximized; WindowPoint = new Point(this.Left, this.Top); WindowSize = new Size(this.Width, this.Height); this.Width = SystemParameters.WorkArea.Width; this.Height = SystemParameters.WorkArea.Height; this.Top = SystemParameters.WorkArea.Top; this.Left = SystemParameters.WorkArea.Left; ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; Path MaxButtonPath = (Path)baseWindowTemplate.FindName("MaxButtonPath", this); MaxButtonPath.Data = Geometry.Parse(PathData.MaxToNormalPath); } else { WinState = JvedioWindowState.Normal; this.Left = WindowPoint.X; this.Width = WindowSize.Width; this.Top = WindowPoint.Y; this.Height = WindowSize.Height; ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; Path MaxButtonPath = (Path)baseWindowTemplate.FindName("MaxButtonPath", this); MaxButtonPath.Data = Geometry.Parse(PathData.MaxPath); } HideMargin(); SizedChangedCompleted?.Invoke(this, new EventArgs()); }
private void InitializeEvent() { try { ControlTemplate baseWindowTemplate = (ControlTemplate)Application.Current.Resources["CommonBaseWindowControlTemplate"]; Border tp = (Border)baseWindowTemplate.FindName("topborder", this); if (null == tp) { return; } tp.MouseLeftButtonDown += delegate { try { this.DragMove(); } catch (InvalidOperationException e) { NLogger.LogHelper.UILogger.DebugFormat("DragMove exception: {0}", e.Message); } }; } catch (Exception ex) { NLogger.LogHelper.UILogger.DebugFormat("InitializeEvent exception: {0}", ex.Message); } }