public DefaultTheme ()
		{
			var style = new Style ();
			style.Setters.Add (new Setter ("FontFamily", "Sans"));
			style.Setters.Add (new Setter ("FontSize", 14d));	
			style.Setters.Add (new Setter ("Foreground", Colors.Black));
			this [typeof(TextBlock)] = style;
			
			style = new Style ();
			style.Setters.Add (new Setter ("BorderThickness", 1.5d));
			style.Setters.Add (new Setter ("BorderColor", Colors.Black));
			style.Setters.Add (new Setter ("Template", new ControlTemplate (ButtonTemplate)));			
			this [typeof(Button)] = style;
			
			style = new Style ();			
			style.Setters.Add (new Setter ("Template", new ControlTemplate (ItemsControlTemplate)));			
			this [typeof(ItemsControl)] = style;
			
			style = new Style ();			
			style.Setters.Add (new Setter ("Template", new ControlTemplate (UserControlTemplate)));			
			this [typeof(UserControl)] = style;
			
			style = new Style ();			
			style.Setters.Add (new Setter ("Template", new ControlTemplate (element => WindowTemplate (element as Window))));			
			this [typeof(Window)] = style;

			style = new Style ();
			style.Setters.Add (new Setter ("ItemsPanel", new StackPanel () { Orientation = Orientation.Horizontal }));
			this [typeof(Menu)] = style;

			style = new Style ();
			style.Setters.Add (new Setter ("Template", new ControlTemplate (MenuItemTemplate)));			
			this [typeof(MenuItem)] = style;
		}
		public DefaultTheme ()
		{
			var style = new Style ();
			style.Setters.Add (new Setter ("FontFamily", "Sans"));
			style.Setters.Add (new Setter ("FontSize", 14d));	
			style.Setters.Add (new Setter ("Foreground", Colors.Black));
			this [typeof(TextBlock)] = style;
			
			style = new Style ();
			style.Setters.Add (new Setter ("BorderThickness", 1.5d));
			style.Setters.Add (new Setter ("BorderColor", Colors.Black));
			style.Setters.Add (new Setter ("Template", new ControlTemplate (ButtonTemplate)));			
			this [typeof(Button)] = style;
			
			style = new Style ();			
			style.Setters.Add (new Setter ("Template", new ControlTemplate (ItemsControlTemplate)));			
			this [typeof(ItemsControl)] = style;
			
			style = new Style ();		
			style.Setters.Add (new Setter ("Template", new ControlTemplate (UserControlTemplate)));			
			this [typeof(UserControl)] = style;
			
			style = new Style ();
			style.Setters.Add (new Setter ("Left", 1d));
			style.Setters.Add (new Setter ("Top", 20d));
			style.Setters.Add (new Setter ("Template", new ControlTemplate (element => WindowTemplate (element as Window))));			
			this [typeof(Window)] = style;

			style = new Style ();
			style.Setters.Add (new Setter ("ItemsPanel", new StackPanel () { Orientation = Orientation.Horizontal }));
			this [typeof(Menu)] = style;

			style = new Style ();
			style.Setters.Add (new Setter ("Template", new ControlTemplate (MenuItemTemplate)));			
			this [typeof(MenuItem)] = style;

			style = new Style ();
			style.Setters.Add (new Setter ("Padding", 0d));
			style.Setters.Add (new Setter ("Background", new SolidColorBrush (new Color (0xd6, 0xd4, 0xd2))));
			style.Setters.Add (new Setter ("BorderThickness", 0d));
			style.Setters.Add (new Setter ("HorizontalAlignment", HorizontalAlignment.Stretch));
			style.Setters.Add (new Setter ("VerticalAlignment", VerticalAlignment.Stretch));
			style.Setters.Add (new Setter ("Template", new ControlTemplate (TabControlTemplate)));			
			this [typeof(TabControl)] = style;
		}
		private void ApplyStyle (Style style)
		{
			foreach (var setter in style.Setters.OfType<Setter>()) {
				var operation = new SetterOperation (this, setter);
				operation.Apply ();

				setterOperations.Add (operation);
			}

			foreach (var trigger in style.Triggers) {
				var condition = new SetterCondition (this, trigger.Property, trigger.Value);

				foreach (var setter in trigger.Setters) {
					var operation = new ConditionalSetterOperation (condition, new SetterOperation (this, setter));
					operation.Apply ();
				
					setterOperations.Add (operation);
				}
			}
		}
		private void RemoveStyle (Style style)
		{
			foreach (var operation in setterOperations) {
				operation.Remove ();
			}

			setterOperations.Clear ();
		}
Example #5
0
		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 ());
		}
		private void ApplyStyle (Style style)
		{
			foreach (var setter in style.Setters.OfType<Setter>()) {
				var property = GetProperty (setter.Property);
				if (property != null)
					property.Value = setter.Value;
			}
		}