Browse Source

ColorPicker: Added SelectedColorChanged event. Added ButtonStyle property so you can style the ColorPicker's dropdown button any way you want.

RichTextBoxFormatBar: Added Text Highlight Color, Font Color, Bullet list and numbered lists.
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
d0b7fe55f4
  1. 32
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs
  2. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Bullets16.png
  3. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/FontColorPicker16.png
  4. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Numbering16.png
  5. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/TextHighlightColorPicker16.png
  6. 243
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml
  7. 92
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml.cs
  8. 9
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs
  9. 7
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml
  10. 11
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj
  11. 7
      ExtendedWPFToolkitSolution_35/Src/WPFToolkit.Extended/Themes/Generic.xaml

32
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<ColorItem>), 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<Color> args = new RoutedPropertyChangedEventArgs<Color>(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<Color>), typeof(ColorPicker));
public event RoutedPropertyChangedEventHandler<Color> SelectedColorChanged
{
add { AddHandler(SelectedColorChangedEvent, value); }
remove { RemoveHandler(SelectedColorChangedEvent, value); }
}
#endregion //Events
#region Methods
private void CloseColorPicker()

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Bullets16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/FontColorPicker16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/Numbering16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/Images/TextHighlightColorPicker16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

243
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml

@ -1,6 +1,7 @@
<UserControl x:Class="Microsoft.Windows.Controls.RichTextBoxFormatBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls"
Background="Transparent"
IsTabStop="False"
x:Name="_window">
@ -11,7 +12,7 @@
<UserControl.Resources>
<Style TargetType="{x:Type Separator}" BasedOn="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"/>
<ControlTemplate x:Key="ThumbControlTemplate" TargetType="{x:Type Thumb}">
<Border Background="Transparent" Cursor="Hand" ToolTip="Click to Drag">
<StackPanel VerticalAlignment="Center" Width="75">
@ -32,7 +33,7 @@
</Line>
</StackPanel>
</Border>
</ControlTemplate>
</ControlTemplate>
<SolidColorBrush x:Key="MouseOverBorderBrush" Color="#FFFFB700" />
<LinearGradientBrush x:Key="MouseOverBackgroundBrush" StartPoint="0,0" EndPoint="0,1" >
@ -145,6 +146,186 @@
</Setter>
</Style>
<Style x:Key="FontColorButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Height" Value="22" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="ToolTipService.InitialShowDelay" Value="900"/>
<Setter Property="ToolTipService.ShowDuration" Value="20000"/>
<Setter Property="ToolTipService.BetweenShowDelay" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid SnapsToDevicePixels="True">
<Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
<Border x:Name="MiddleBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2">
<Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid>
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/FontColorPicker16.png" Width="16" Height="16" />
<Rectangle Grid.Row="1" Fill="{TemplateBinding Background}" Height="4" Margin="0,12,0,0" />
</Grid>
<Path Grid.Column="1" Width="7" Height="4"
Data="M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z" Fill="#FF000000"/>
</Grid>
</Border>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource MouseOverBackgroundBrush}"/>
<Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource MouseOverBorderBrush}"/>
<Setter Property="BorderBrush" TargetName="InnerBorder" Value="#80FFFFFF"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="OuterBorder" Value="#FF9E9E9E"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource CheckedBackgroundBrush}"/>
<Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource CheckedBorderBrush}"/>
<Setter Property="BorderBrush" TargetName="InnerBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFE7CBAD" Offset="0"/>
<GradientStop Color="#FFF7D7B5" Offset="0.1"/>
<GradientStop Color="#FFFFD38C" Offset="0.36"/>
<GradientStop Color="#FFFFC75A" Offset="0.36"/>
<GradientStop Color="#FFFFEFA5" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource PressedBackgroundBrush}"/>
<Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource PressedBorderBrush}"/>
<Setter Property="BorderBrush" TargetName="InnerBorder" Value="Transparent"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsChecked" Value="True"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="MiddleBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#40FFFEFE" Offset="0"/>
<GradientStop Color="#40FFFEFE" Offset="0.39"/>
<GradientStop Color="#20FFCE68" Offset="0.39"/>
<GradientStop Color="#20FFCE68" Offset="0.69"/>
<GradientStop Color="#10FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="FontBackgrounColorButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Height" Value="22" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="ToolTipService.InitialShowDelay" Value="900"/>
<Setter Property="ToolTipService.ShowDuration" Value="20000"/>
<Setter Property="ToolTipService.BetweenShowDelay" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid SnapsToDevicePixels="True">
<Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
<Border x:Name="MiddleBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2">
<Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" CornerRadius="2" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid>
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/TextHighlightColorPicker16.png" Width="16" Height="16" />
<Rectangle Grid.Row="1" Fill="{TemplateBinding Background}" Height="4" Margin="0,12,0,0" />
</Grid>
<Path Grid.Column="1" Width="7" Height="4"
Data="M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z" Fill="#FF000000"/>
</Grid>
</Border>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource MouseOverBackgroundBrush}"/>
<Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource MouseOverBorderBrush}"/>
<Setter Property="BorderBrush" TargetName="InnerBorder" Value="#80FFFFFF"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="OuterBorder" Value="#FF9E9E9E"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource CheckedBackgroundBrush}"/>
<Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource CheckedBorderBrush}"/>
<Setter Property="BorderBrush" TargetName="InnerBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFE7CBAD" Offset="0"/>
<GradientStop Color="#FFF7D7B5" Offset="0.1"/>
<GradientStop Color="#FFFFD38C" Offset="0.36"/>
<GradientStop Color="#FFFFC75A" Offset="0.36"/>
<GradientStop Color="#FFFFEFA5" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="OuterBorder" Value="{StaticResource PressedBackgroundBrush}"/>
<Setter Property="BorderBrush" TargetName="OuterBorder" Value="{StaticResource PressedBorderBrush}"/>
<Setter Property="BorderBrush" TargetName="InnerBorder" Value="Transparent"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsChecked" Value="True"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="MiddleBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#40FFFEFE" Offset="0"/>
<GradientStop Color="#40FFFEFE" Offset="0.39"/>
<GradientStop Color="#20FFCE68" Offset="0.39"/>
<GradientStop Color="#20FFCE68" Offset="0.69"/>
<GradientStop Color="#10FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Border CornerRadius="3" BorderThickness="1" BorderBrush="Gray" Background="WhiteSmoke">
@ -160,41 +341,79 @@
<StackPanel Grid.Row="1">
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="_cmbFontFamilies" IsEditable="True" Width="110"
SelectionChanged="FontFamily_SelectionChanged"/>
<ComboBox x:Name="_cmbFontSizes" IsEditable="True" Width="45"
SelectionChanged="FontSize_SelectionChanged"/>
<ComboBox x:Name="_cmbFontFamilies" IsEditable="True" Width="100"
SelectionChanged="FontFamily_SelectionChanged"
ToolTip="Font Family"/>
<ComboBox x:Name="_cmbFontSizes" IsEditable="True" Width="43"
SelectionChanged="FontSize_SelectionChanged"
ToolTip="Font Size"/>
<Separator />
<ToggleButton x:Name="_btnBullets" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="EditingCommands.ToggleBullets" CommandTarget="{Binding ElementName=_window, Path=Target}"
Click="Bullets_Clicked"
ToolTip="Bullets">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/Bullets16.png" />
</ToggleButton>
<ToggleButton x:Name="_btnNumbers" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="EditingCommands.ToggleNumbering" CommandTarget="{Binding ElementName=_window, Path=Target}"
Click="Numbers_Clicked"
ToolTip="Numbering">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/Numbering16.png" />
</ToggleButton>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
<ToggleButton x:Name="_btnBold" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=_window, Path=Target}">
Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=_window, Path=Target}"
ToolTip="Bold">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/Bold16.png" />
</ToggleButton>
<ToggleButton x:Name="_btnItalic" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="{x:Static EditingCommands.ToggleItalic}" CommandTarget="{Binding ElementName=_window, Path=Target}">
Command="{x:Static EditingCommands.ToggleItalic}" CommandTarget="{Binding ElementName=_window, Path=Target}"
ToolTip="Italic">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/Italic16.png" />
</ToggleButton>
<ToggleButton x:Name="_btnUnderline" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="{x:Static EditingCommands.ToggleUnderline}" CommandTarget="{Binding ElementName=_window, Path=Target}">
Command="{x:Static EditingCommands.ToggleUnderline}" CommandTarget="{Binding ElementName=_window, Path=Target}"
ToolTip="Underline">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/Underline16.png" />
</ToggleButton>
<Separator />
<RadioButton x:Name="_btnAlignLeft" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="{x:Static EditingCommands.AlignLeft}" CommandTarget="{Binding ElementName=_window, Path=Target}" >
Command="{x:Static EditingCommands.AlignLeft}" CommandTarget="{Binding ElementName=_window, Path=Target}"
ToolTip="Align Left">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/LeftAlign16.png" />
</RadioButton>
<RadioButton x:Name="_btnAlignCenter" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="{x:Static EditingCommands.AlignCenter}" CommandTarget="{Binding ElementName=_window, Path=Target}" >
Command="{x:Static EditingCommands.AlignCenter}" CommandTarget="{Binding ElementName=_window, Path=Target}"
ToolTip="Align Center">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/CenterAlign16.png" />
</RadioButton>
<RadioButton x:Name="_btnAlignRight" Style="{StaticResource FormatBarToggleButtonStyle}"
Command="{x:Static EditingCommands.AlignRight}" CommandTarget="{Binding ElementName=_window, Path=Target}" >
Command="{x:Static EditingCommands.AlignRight}" CommandTarget="{Binding ElementName=_window, Path=Target}"
ToolTip="Align Right">
<Image Source="/WPFToolkit.Extended;component/RichTextBoxFormatBar/Images/RightAlign16.png" />
</RadioButton>
<Separator />
<extToolkit:ColorPicker x:Name="_cmbFontBackgroundColor" BorderThickness="0"
ButtonStyle="{StaticResource FontBackgrounColorButtonStyle}"
SelectedColorChanged="FontBackgroundColor_SelectedColorChanged"
ToolTip="Text Highlight Color"/>
<extToolkit:ColorPicker x:Name="_cmbFontColor" BorderThickness="0"
ButtonStyle="{StaticResource FontColorButtonStyle}"
SelectedColorChanged="FontColor_SelectedColorChanged"
ToolTip="Font Color"/>
</StackPanel>
</StackPanel>

92
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<Color> e)
{
UpdateVisualState();
Color selectedColor = (Color)e.NewValue;
ApplyPropertyValueToSelectedText(TextElement.ForegroundProperty, new SolidColorBrush(selectedColor));
}
private void FontBackgroundColor_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> 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;
}
/// <summary>
/// Updates the visual state of the List styles, such as Numbers and Bullets.
/// </summary>
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;
}
}
}
/// <summary>
/// Checks to see if both selection lists are checked. (Bullets and Numbers)
/// </summary>
/// <returns></returns>
private bool BothSelectionListsAreChecked()
{
return _btnBullets.IsChecked == true && _btnNumbers.IsChecked == true;
}
void ApplyPropertyValueToSelectedText(DependencyProperty formattingProperty, object value)
{
if (value == null)

9
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
/// </summary>
void ShowAdorner()
{
if (_adorner.Visibility == Visibility.Visible)
return;
VerifyAdornerLayer();
Control adorningEditor = _toolbar as Control;
@ -182,7 +185,7 @@ namespace Microsoft.Windows.Controls
/// </summary>
void HideAdorner()
{
if (AdornerIsVisible)
if (IsAdornerVisible)
{
_adorner.Visibility = Visibility.Collapsed;
_adorner.Child = null;

7
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -695,13 +695,16 @@
</DataTemplate>
<Style TargetType="{x:Type local:ColorPicker}">
<Setter Property="ButtonStyle" Value="{StaticResource ColorPickerToggleButton}" />
<Setter Property="BorderBrush" Value="{StaticResource ColorPickerDarkBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorPicker}">
<Grid>
<Border BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" BorderThickness="1" CornerRadius="0">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0">
<Grid>
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{StaticResource ColorPickerToggleButton}" MinHeight="22">
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{TemplateBinding ButtonStyle}" MinHeight="22">
<ToggleButton.Background>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</ToggleButton.Background>

11
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -153,7 +153,16 @@
<ItemGroup>
<Resource Include="RichTextBoxFormatBar\Images\Underline16.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="RichTextBoxFormatBar\Images\FontColorPicker16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="RichTextBoxFormatBar\Images\TextHighlightColorPicker16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="RichTextBoxFormatBar\Images\Bullets16.png" />
<Resource Include="RichTextBoxFormatBar\Images\Numbering16.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

7
ExtendedWPFToolkitSolution_35/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -696,13 +696,16 @@
</DataTemplate>
<Style TargetType="{x:Type local:ColorPicker}">
<Setter Property="ButtonStyle" Value="{StaticResource ColorPickerToggleButton}" />
<Setter Property="BorderBrush" Value="{StaticResource ColorPickerDarkBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorPicker}">
<Grid>
<Border BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" BorderThickness="1" CornerRadius="0">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0">
<Grid>
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{StaticResource ColorPickerToggleButton}" MinHeight="22">
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{TemplateBinding ButtonStyle}" MinHeight="22">
<ToggleButton.Background>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</ToggleButton.Background>

Loading…
Cancel
Save