public MathRegion () { Focusable = true; var style = new Style (); style.Setters.Add (new Setter ("BorderColor", Colors.Bisque)); var trigger = new Trigger () {Property = "IsMouseOver", Value = true}; trigger.Setters.Add (new Setter ("BorderColor", Colors.Red)); style.Triggers.Add (trigger); border = new Border (); border.Style = style; BindingOperations.SetBinding (this, "DataContext.Root", border.GetProperty ("Child"), new TokenAreaConverter ()); Content = new AdornerDecorator () { Child = border }; AdornerLayer.GetAdornerLayer (border).Add (new CursorLines (this)); LostKeyboardFocusEvent += HandleLostKeyboardFocusEvent; new InsertCharacterProcessor (this); var plusKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.PlusCommand", plusKeyBinding.GetProperty ("Command")); plusKeyBinding.Gesture = new KeyGesture (Key.OemPlus, ModifierKeys.Shift); var minusKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.MinusCommand", minusKeyBinding.GetProperty ("Command")); minusKeyBinding.Gesture = new KeyGesture (Key.OemMinus); var multiplicationBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.MultiplicationCommand", multiplicationBinding.GetProperty ("Command")); multiplicationBinding.Gesture = new KeyGesture (Key.D8, ModifierKeys.Shift); var divideBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.DivideCommand", divideBinding.GetProperty ("Command")); divideBinding.Gesture = new KeyGesture (Key.OemQuestion); var assignmentBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.AssignmentCommand", assignmentBinding.GetProperty ("Command")); assignmentBinding.Gesture = new KeyGesture (Key.OemSemicolon, ModifierKeys.Shift); var resultKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.ResultCommand", resultKeyBinding.GetProperty ("Command")); resultKeyBinding.Gesture = new KeyGesture (Key.OemPlus); var leftKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.LeftCommand", leftKeyBinding.GetProperty ("Command")); leftKeyBinding.Gesture = new KeyGesture (Key.Left); var rightKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.RightCommand", rightKeyBinding.GetProperty ("Command")); rightKeyBinding.Gesture = new KeyGesture (Key.Right); var openBracketBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.OpenBracketCommand", openBracketBinding.GetProperty ("Command")); openBracketBinding.Gesture = new KeyGesture (Key.D9, ModifierKeys.Shift); var closeBracketBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.CloseBracketCommand", closeBracketBinding.GetProperty ("Command")); closeBracketBinding.Gesture = new KeyGesture (Key.D0, ModifierKeys.Shift); var commaBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.CommaCommand", commaBinding.GetProperty ("Command")); commaBinding.Gesture = new KeyGesture (Key.OemComma); var exponentiationBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.ExponentiationCommand", exponentiationBinding.GetProperty ("Command")); exponentiationBinding.Gesture = new KeyGesture (Key.D6, ModifierKeys.Shift); var squareRootBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.SquareRootCommand", squareRootBinding.GetProperty ("Command")); squareRootBinding.Gesture = new KeyGesture (Key.OemBackslash); var absoluteBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.AbsoluteCommand", absoluteBinding.GetProperty ("Command")); absoluteBinding.Gesture = new KeyGesture (Key.OemBackslash, ModifierKeys.Shift); InputBindings.Add (plusKeyBinding); InputBindings.Add (minusKeyBinding); InputBindings.Add (multiplicationBinding); InputBindings.Add (divideBinding); InputBindings.Add (assignmentBinding); InputBindings.Add (resultKeyBinding); InputBindings.Add (leftKeyBinding); InputBindings.Add (rightKeyBinding); InputBindings.Add (openBracketBinding); InputBindings.Add (closeBracketBinding); InputBindings.Add (commaBinding); InputBindings.Add (exponentiationBinding); InputBindings.Add (squareRootBinding); InputBindings.Add (absoluteBinding); selection = BuildProperty<Selection> ("Selection"); insertCharacterCommand = BuildProperty<ICommand> ("InsertCharacterCommand"); evaluateCommand = BuildProperty<ICommand> ("EvaluateCommand"); selection.DependencyPropertyValueChanged += HandleSelectionChanged; BindingOperations.SetBinding (this, "DataContext.Selection", GetProperty ("Selection")); BindingOperations.SetBinding (this, "DataContext.InsertCharacterCommand", GetProperty ("InsertCharacterCommand")); BindingOperations.SetBinding (this, "DataContext.EvaluateCommand", GetProperty ("EvaluateCommand")); BindingOperations.SetBinding (this, "DataContext.HasError", GetProperty ("Background"), new HasErrorToBrushesConverter ()); }
public MathRegion () { Focusable = true; border = new Border () { BorderColor = Colors.Bisque }; BindingOperations.SetBinding (this, "DataContext.Root", border.GetProperty ("Child"), new TokenAreaConverter ()); Content = new AdornerDecorator () { Child = border }; AdornerLayer.GetAdornerLayer (border).Add (new CursorLines (this)); MouseEnterEvent += HandleMouseEnterEvent; MouseLeaveEvent += HandleMouseLeaveEvent; LostKeyboardFocusEvent += HandleLostKeyboardFocusEvent; new InsertCharacterProcessor (this); var plusKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.PlusCommand", plusKeyBinding.GetProperty ("Command")); plusKeyBinding.Gesture = new KeyGesture (Key.Add); var minusKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.MinusCommand", minusKeyBinding.GetProperty ("Command")); minusKeyBinding.Gesture = new KeyGesture (Key.Subtract); var multiplicationBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.MultiplicationCommand", multiplicationBinding.GetProperty ("Command")); multiplicationBinding.Gesture = new KeyGesture (Key.Multiply); var divideBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.DivideCommand", divideBinding.GetProperty ("Command")); divideBinding.Gesture = new KeyGesture (Key.Oem2); var assignmentBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.AssignmentCommand", assignmentBinding.GetProperty ("Command")); assignmentBinding.Gesture = new KeyGesture (Key.Oem1, ModifierKeys.Shift); var resultKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.ResultCommand", resultKeyBinding.GetProperty ("Command")); resultKeyBinding.Gesture = new KeyGesture (Key.OemPlus); var leftKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.LeftCommand", leftKeyBinding.GetProperty ("Command")); leftKeyBinding.Gesture = new KeyGesture (Key.Left); var rightKeyBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.RightCommand", rightKeyBinding.GetProperty ("Command")); rightKeyBinding.Gesture = new KeyGesture (Key.Right); var openBracketBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.OpenBracketCommand", openBracketBinding.GetProperty ("Command")); openBracketBinding.Gesture = new KeyGesture (Key.D9, ModifierKeys.Shift); var closeBracketBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.CloseBracketCommand", closeBracketBinding.GetProperty ("Command")); closeBracketBinding.Gesture = new KeyGesture (Key.D0, ModifierKeys.Shift); var commaBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.CommaCommand", commaBinding.GetProperty ("Command")); commaBinding.Gesture = new KeyGesture (Key.OemComma); var exponentiationBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.ExponentiationCommand", exponentiationBinding.GetProperty ("Command")); exponentiationBinding.Gesture = new KeyGesture (Key.D6, ModifierKeys.Shift); var squareRootBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.SquareRootCommand", squareRootBinding.GetProperty ("Command")); squareRootBinding.Gesture = new KeyGesture (Key.Back); var absoluteBinding = new KeyBinding (); BindingOperations.SetBinding (this, "DataContext.AbsoluteCommand", absoluteBinding.GetProperty ("Command")); absoluteBinding.Gesture = new KeyGesture (Key.Oem5, ModifierKeys.Shift); InputBindings.Add (plusKeyBinding); InputBindings.Add (minusKeyBinding); InputBindings.Add (multiplicationBinding); InputBindings.Add (divideBinding); InputBindings.Add (assignmentBinding); InputBindings.Add (resultKeyBinding); InputBindings.Add (leftKeyBinding); InputBindings.Add (rightKeyBinding); InputBindings.Add (openBracketBinding); InputBindings.Add (closeBracketBinding); InputBindings.Add (commaBinding); InputBindings.Add (exponentiationBinding); InputBindings.Add (squareRootBinding); InputBindings.Add (absoluteBinding); selection = BuildProperty<Selection> ("Selection"); insertCharacterCommand = BuildProperty<ICommand> ("InsertCharacterCommand"); evaluateCommand = BuildProperty<ICommand> ("EvaluateCommand"); BindingOperations.SetBinding (this, "DataContext.Selection", GetProperty ("Selection")); BindingOperations.SetBinding (this, "DataContext.InsertCharacterCommand", GetProperty ("InsertCharacterCommand")); BindingOperations.SetBinding (this, "DataContext.EvaluateCommand", GetProperty ("EvaluateCommand")); BindingOperations.SetBinding (this, "DataContext.HasError", GetProperty ("Background"), new HasErrorToBrushesConverter ()); }