diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs index a3347b2c..610cea70 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs @@ -33,6 +33,17 @@ namespace Microsoft.Windows.Controls #endregion //AvailableColors + #region ButtonStyle + + public static readonly DependencyProperty ButtonStyleProperty = DependencyProperty.Register("ButtonStyle", typeof(Style), typeof(ColorPicker)); + public Style ButtonStyle + { + get { return (Style)GetValue(ButtonStyleProperty); } + set { SetValue(ButtonStyleProperty, value); } + } + + #endregion //ButtonStyle + #region RecenColors public static readonly DependencyProperty RecentColorsProperty = DependencyProperty.Register("RecentColors", typeof(ObservableCollection), typeof(ColorPicker), new UIPropertyMetadata(null)); @@ -46,7 +57,7 @@ namespace Microsoft.Windows.Controls #region SelectedColor - public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(Colors.White, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedColorPropertyChanged))); + public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(Colors.Black, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedColorPropertyChanged))); public Color SelectedColor { get { return (Color)GetValue(SelectedColorProperty); } @@ -57,12 +68,14 @@ namespace Microsoft.Windows.Controls { ColorPicker colorPicker = (ColorPicker)d; if (colorPicker != null) - colorPicker.SelectedColorChanged((Color)e.OldValue, (Color)e.NewValue); + colorPicker.OnSelectedColorChanged((Color)e.OldValue, (Color)e.NewValue); } - private void SelectedColorChanged(Color oldValue, Color newValue) + private void OnSelectedColorChanged(Color oldValue, Color newValue) { - + RoutedPropertyChangedEventArgs args = new RoutedPropertyChangedEventArgs(oldValue, newValue); + args.RoutedEvent = ColorPicker.SelectedColorChangedEvent; + RaiseEvent(args); } #endregion //SelectedColor @@ -140,6 +153,17 @@ namespace Microsoft.Windows.Controls #endregion //Event Handlers + #region Events + + public static readonly RoutedEvent SelectedColorChangedEvent = EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler), typeof(ColorPicker)); + public event RoutedPropertyChangedEventHandler SelectedColorChanged + { + add { AddHandler(SelectedColorChangedEvent, value); } + remove { RemoveHandler(SelectedColorChangedEvent, value); } + } + + #endregion //Events + #region Methods private void CloseColorPicker() diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Bullets16.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Bullets16.png new file mode 100644 index 00000000..73e7c15e Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Bullets16.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/FontColorPicker16.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/FontColorPicker16.png new file mode 100644 index 00000000..d9207308 Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/FontColorPicker16.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Numbering16.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Numbering16.png new file mode 100644 index 00000000..03f6fde2 Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Numbering16.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/TextHighlightColorPicker16.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/TextHighlightColorPicker16.png new file mode 100644 index 00000000..4a3783f2 Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/TextHighlightColorPicker16.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml index 6d919c41..a2ebd824 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml @@ -1,6 +1,7 @@  @@ -11,7 +12,7 @@ + + + + @@ -160,41 +341,79 @@ - - + + + + + + + + + + + + + + + Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=_window, Path=Target}" + ToolTip="Bold"> + Command="{x:Static EditingCommands.ToggleItalic}" CommandTarget="{Binding ElementName=_window, Path=Target}" + ToolTip="Italic"> + Command="{x:Static EditingCommands.ToggleUnderline}" CommandTarget="{Binding ElementName=_window, Path=Target}" + ToolTip="Underline"> + Command="{x:Static EditingCommands.AlignLeft}" CommandTarget="{Binding ElementName=_window, Path=Target}" + ToolTip="Align Left"> + Command="{x:Static EditingCommands.AlignCenter}" CommandTarget="{Binding ElementName=_window, Path=Target}" + ToolTip="Align Center"> + Command="{x:Static EditingCommands.AlignRight}" CommandTarget="{Binding ElementName=_window, Path=Target}" + ToolTip="Align Right"> + + + + + + diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml.cs index 65e78914..d7c65788 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml.cs @@ -27,12 +27,6 @@ namespace Microsoft.Windows.Controls private static void OnRichTextBoxPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RichTextBoxFormatBar formatBar = d as RichTextBoxFormatBar; - formatBar.HookupRichTextBoxEvents(); - } - - private void HookupRichTextBoxEvents() - { - Target.SelectionChanged += RichTextBox_SelectionChanged; } #endregion //RichTextBox @@ -52,13 +46,16 @@ namespace Microsoft.Windows.Controls } #endregion - + #region Constructors public RichTextBoxFormatBar() { InitializeComponent(); Loaded += FormatToolbar_Loaded; + + _cmbFontFamilies.ItemsSource = Fonts.SystemFontFamilies; + _cmbFontSizes.ItemsSource = FontSizes; } #endregion //Constructors @@ -67,8 +64,7 @@ namespace Microsoft.Windows.Controls void FormatToolbar_Loaded(object sender, RoutedEventArgs e) { - _cmbFontFamilies.ItemsSource = Fonts.SystemFontFamilies; - _cmbFontSizes.ItemsSource = FontSizes; + UpdateVisualState(); } private void FontFamily_SelectionChanged(object sender, SelectionChangedEventArgs e) @@ -88,9 +84,32 @@ namespace Microsoft.Windows.Controls ApplyPropertyValueToSelectedText(TextElement.FontSizeProperty, e.AddedItems[0]); } - void RichTextBox_SelectionChanged(object sender, RoutedEventArgs e) + void FontColor_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) { - UpdateVisualState(); + Color selectedColor = (Color)e.NewValue; + ApplyPropertyValueToSelectedText(TextElement.ForegroundProperty, new SolidColorBrush(selectedColor)); + } + + private void FontBackgroundColor_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) + { + Color selectedColor = (Color)e.NewValue; + ApplyPropertyValueToSelectedText(TextElement.BackgroundProperty, new SolidColorBrush(selectedColor)); + } + + private void Bullets_Clicked(object sender, RoutedEventArgs e) + { + if (BothSelectionListsAreChecked()) + { + _btnNumbers.IsChecked = false; + } + } + + private void Numbers_Clicked(object sender, RoutedEventArgs e) + { + if (BothSelectionListsAreChecked()) + { + _btnBullets.IsChecked = false; + } } private void DragWidget_DragDelta(object sender, DragDeltaEventArgs e) @@ -107,6 +126,9 @@ namespace Microsoft.Windows.Controls UpdateToggleButtonState(); UpdateSelectedFontFamily(); UpdateSelectedFontSize(); + UpdateFontColor(); + UpdateFontBackgroundColor(); + UpdateSelectionListType(); } private void UpdateToggleButtonState() @@ -142,6 +164,54 @@ namespace Microsoft.Windows.Controls _cmbFontSizes.SelectedValue = (value == DependencyProperty.UnsetValue) ? null : value; } + private void UpdateFontColor() + { + object value = Target.Selection.GetPropertyValue(TextElement.ForegroundProperty); + Color currentColor = (Color)((value == DependencyProperty.UnsetValue) ? Colors.Black : ((SolidColorBrush)value).Color); + _cmbFontColor.SelectedColor = currentColor; + } + + private void UpdateFontBackgroundColor() + { + object value = Target.Selection.GetPropertyValue(TextElement.BackgroundProperty); + Color currentColor = (Color)((value == null || value == DependencyProperty.UnsetValue) ? Colors.White : ((SolidColorBrush)value).Color); + _cmbFontBackgroundColor.SelectedColor = currentColor; + } + + /// + /// Updates the visual state of the List styles, such as Numbers and Bullets. + /// + private void UpdateSelectionListType() + { + //uncheck both + _btnBullets.IsChecked = false; + _btnNumbers.IsChecked = false; + + Paragraph startParagraph = Target.Selection.Start.Paragraph; + Paragraph endParagraph = Target.Selection.End.Paragraph; + if (startParagraph != null && endParagraph != null && (startParagraph.Parent is ListItem) && (endParagraph.Parent is ListItem) && object.ReferenceEquals(((ListItem)startParagraph.Parent).List, ((ListItem)endParagraph.Parent).List)) + { + TextMarkerStyle markerStyle = ((ListItem)startParagraph.Parent).List.MarkerStyle; + if (markerStyle == TextMarkerStyle.Disc) //bullets + { + _btnBullets.IsChecked = true; + } + else if (markerStyle == TextMarkerStyle.Decimal) //numbers + { + _btnNumbers.IsChecked = true; + } + } + } + + /// + /// Checks to see if both selection lists are checked. (Bullets and Numbers) + /// + /// + private bool BothSelectionListsAreChecked() + { + return _btnBullets.IsChecked == true && _btnNumbers.IsChecked == true; + } + void ApplyPropertyValueToSelectedText(DependencyProperty formattingProperty, object value) { if (value == null) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs index 7f5cdce2..8fbc1e31 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs @@ -43,7 +43,7 @@ namespace Microsoft.Windows.Controls #endregion //FormatBar - bool AdornerIsVisible + public bool IsAdornerVisible { get { return _adorner.Visibility == Visibility.Visible; } } @@ -91,7 +91,7 @@ namespace Microsoft.Windows.Controls { //this fixes the bug when applying text transformations the text would lose it's highlight. That was because the RichTextBox was losing focus //so we just give it focus again and it seems to do the trick of re-highlighting it. - if (!_richTextBox.IsFocused) + if (!_richTextBox.IsFocused && !_richTextBox.Selection.IsEmpty) _richTextBox.Focus(); } @@ -125,6 +125,9 @@ namespace Microsoft.Windows.Controls /// void ShowAdorner() { + if (_adorner.Visibility == Visibility.Visible) + return; + VerifyAdornerLayer(); Control adorningEditor = _toolbar as Control; @@ -182,7 +185,7 @@ namespace Microsoft.Windows.Controls /// void HideAdorner() { - if (AdornerIsVisible) + if (IsAdornerVisible) { _adorner.Visibility = Visibility.Collapsed; _adorner.Child = null; diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml index 279d641a..b0cab504 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml @@ -695,13 +695,16 @@