private static UIElement ItemsControlTemplate (UIElement element) { var border = new Border (); BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding")); BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background")); BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness")); BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor")); BindingOperations.SetBinding (element.GetProperty ("ItemsPanel"), border.GetProperty ("Child")); return border; }
private static UIElement ButtonTemplate (UIElement element) { var border = new Border (); border.CornerRadius = new CornerRadius (3); BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding")); BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background")); BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness")); BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor")); BindingOperations.SetBinding (element.GetProperty ("Content"), border.GetProperty ("Child")); return border; }
private static UIElement TabHeaderTemplate (object o) { var item = o as ItemView; var tabHeader = new ContentControl (); BindingOperations.SetBinding (item.Visual.GetProperty ("Header"), tabHeader.GetProperty ("Content")); var headerBorder = new Border () { Background = new SolidColorBrush(new Color(0xf2, 0xf1, 0xf0)), Child = tabHeader, Padding = new Thickness(5), BorderThickness = 0, }; return headerBorder; }
private static UIElement TabControlTemplate (UIElement element) { var grid = new Grid () { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; grid.RowDefinitions.Add (new RowDefinition () { Height = GridLength.Auto }); grid.RowDefinitions.Add (new RowDefinition ()); grid.ColumnDefinitions.Add (new ColumnDefinition ()); var selectedTabContent = new ContentControl () { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; BindingOperations.SetBinding (element, "SelectedItem.Content", selectedTabContent.GetProperty ("Content")); var headerPanel = new ItemsControl () { ItemsPanel = new StackPanel() { Orientation = Orientation.Horizontal }, ItemTemplate = new DataTemplate(TabHeaderTemplate), }; BindingOperations.SetBinding (element.GetProperty ("Items"), headerPanel.GetProperty ("ItemsSource")); grid.Children.Add (headerPanel); grid.Children.Add (selectedTabContent); grid.SetRow (0, headerPanel); grid.SetColumn (0, headerPanel); grid.SetRow (1, selectedTabContent); grid.SetColumn (0, selectedTabContent); var border = new Border () { Child = grid, }; BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding")); BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background")); BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness")); BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor")); return border; }
private static UIElement WindowTemplate (Window element) { var grid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch}; grid.RowDefinitions.Add (new RowDefinition () {Height = GridLength.Auto}); grid.RowDefinitions.Add (new RowDefinition ()); grid.ColumnDefinitions.Add (new ColumnDefinition ()); var titleGrid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch}; titleGrid.RowDefinitions.Add (new RowDefinition ()); titleGrid.ColumnDefinitions.Add (new ColumnDefinition ()); titleGrid.ColumnDefinitions.Add (new ColumnDefinition () { Width = GridLength.Auto }); var title = new TextBlock (); title.Foreground = Colors.White; title.HorizontalAlignment = HorizontalAlignment.Center; BindingOperations.SetBinding (element.GetProperty ("Title"), title.GetProperty ("Text")); var closeButton = CloseButton (); closeButton.Click += (sender, e) => element.Close (); titleGrid.Children.Add (title); titleGrid.Children.Add (closeButton); titleGrid.SetColumn (0, title); titleGrid.SetColumn (1, closeButton); var titleThumb = new Thumb () { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Template = new ControlTemplate(t => titleGrid) }; titleThumb.DragDelta += (sender, e) => { element.Left += e.HorizontalChange; element.Top += e.VerticalChange; }; var titleBorder = new Border (); titleBorder.Background = GetTitleBrush (); titleBorder.Child = titleThumb; titleBorder.Padding = new Thickness (3); grid.Children.Add (titleBorder); grid.SetRow (0, titleBorder); var border = new Border (); BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding")); BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background")); BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness")); BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor")); BindingOperations.SetBinding (element.GetProperty ("Content"), border.GetProperty ("Child")); grid.Children.Add (border); grid.SetRow (1, border); return grid; }
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 ()); }