/// <summary> /// 현재 나타내고자 하는 UserControl로 바꾸어준다. /// 즉, 현재 보이고 있는 UserControl은 사라지게 하고, 바꾸고자 하는 UserControl로 변경. /// </summary> /// <param name="switchCtrlTarget"></param> public void SwitchCustomControl(CustomControlType switchCtrlTarget) { PopCustomCtrl(); PushCustomCtrl(GetCustomCtrl(switchCtrlTarget)); }
// 미리 정의해둔 Type을 통해, UserControl을 반환한다. public CustomControlModel GetCustomCtrl(CustomControlType customCtrlType) { return(customCtrlItems.Where(x => x.userCtrlType == customCtrlType).FirstOrDefault()); }
// Selects the current/active custom control. public void Select(CustomControlType customControlType) { switch (customControlType) { case CustomControlType.Constant: CurrentControl = _controlConstant; break; case CustomControlType.Variable: CurrentControl = _controlVariable; break; case CustomControlType.Function: CurrentControl = _controlFunction; break; case CustomControlType.Group: CurrentControl = _controlGroup; break; case CustomControlType.Reference: CurrentControl = _controlReference; break; case CustomControlType.Keyword: CurrentControl = _controlKeyword; break; } }
/// <summary> /// 초기에 UserControl들을 설정해주기 위한 메서드. /// 관리하고자 하는 UserControl과 UserControl의 Type에 대한 정보를 인자로 넘겨 설정. /// /// [HOW TO USE] : MainWindow.xaml에 만든 UserControl들을 부른 후, MainWindow.xaml.cs에서 설정해 줄 것. /// </summary> /// <param name="userCtrl", 설정하고자 하는 UserControl></param> /// <param name="customCtrlType", 설정하고자 하는 UserControl의 Type></param> public void SetCustomCtrl(CustomControlModel userCtrl, CustomControlType customCtrlType) { userCtrl.userCtrlType = customCtrlType; customCtrlItems.Add(userCtrl); userCtrl.Visibility = Visibility.Collapsed; }
// When the user changes the type of an element (e.g. constant to variable) the control must be replaced. public void ReplaceWith(CustomControlType customControlType) { Control parent = CurrentControl.Parent; CustomControl newMe = CurrentControl; CustomControl me = CurrentControl; switch (customControlType) { case CustomControlType.Constant: if (CurrentControl == _controlConstant) return; newMe = _controlConstant; _updateType("constant"); break; case CustomControlType.Variable: if (CurrentControl == _controlVariable) return; newMe = _controlVariable; _updateType("variable"); break; case CustomControlType.Function: if (CurrentControl == _controlFunction) return; newMe = _controlFunction; _updateType("function"); break; case CustomControlType.Group: if (CurrentControl == _controlGroup) return; newMe = _controlGroup; break; case CustomControlType.Reference: if (CurrentControl == _controlReference) return; newMe = _controlReference; _updateType("reference"); break; case CustomControlType.Keyword: if (CurrentControl == _controlKeyword) return; newMe = _controlKeyword; _updateType("keyword"); break; } parent.SuspendLayout(); parent.Controls.Add(newMe); parent.Controls.SetChildIndex(newMe, parent.Controls.GetChildIndex(me)); parent.Controls.Remove(me); CurrentControl = newMe; CurrentControl.Focus(); CurrentControl.UpdateValues(); parent.ResumeLayout(); //Scroll control into view if (CurrentControl.ParentForm is ViewerForm) { var viewer = ((ViewerForm)CurrentControl.ParentForm).elementViewer; viewer.VerticalScroll.Value = viewer.VerticalScroll.Maximum; viewer.ScrollControlIntoView(CurrentControl); } }