Browse Source

ColorPicker: fixed bug where the popup would stay open when other controls receive focus. Restyled the colorPicker.

RichTextBoxFormatBar: fixed font highlight toogle button to display the current highlight color
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
53ead6bd64
  1. 66
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs
  2. 22
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs
  3. 6
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBar.xaml
  4. 156
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml
  5. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

66
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs

@ -5,6 +5,7 @@ using System.Windows.Media;
using System.Windows.Controls.Primitives;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Windows.Input;
namespace Microsoft.Windows.Controls
{
@ -12,7 +13,7 @@ namespace Microsoft.Windows.Controls
{
#region Members
ToggleButton _colorPickerToggleButton;
//ToggleButton _colorPickerToggleButton;
Popup _colorPickerCanvasPopup;
ListBox _availableColors;
ListBox _standardColors;
@ -42,9 +43,20 @@ namespace Microsoft.Windows.Controls
set { SetValue(ButtonStyleProperty, value); }
}
#endregion //ButtonStyle
#endregion //ButtonStyle
#region RecenColors
#region IsOpen
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register("IsOpen", typeof(bool), typeof(ColorPicker), new UIPropertyMetadata(false));
public bool IsOpen
{
get { return (bool)GetValue(IsOpenProperty); }
set { SetValue(IsOpenProperty, value); }
}
#endregion //IsOpen
#region RecentColors
public static readonly DependencyProperty RecentColorsProperty = DependencyProperty.Register("RecentColors", typeof(ObservableCollection<ColorItem>), typeof(ColorPicker), new UIPropertyMetadata(null));
public ObservableCollection<ColorItem> RecentColors
@ -73,6 +85,8 @@ namespace Microsoft.Windows.Controls
private void OnSelectedColorChanged(Color oldValue, Color newValue)
{
//SelectedColorText = newValue.GetColorName();
RoutedPropertyChangedEventArgs<Color> args = new RoutedPropertyChangedEventArgs<Color>(oldValue, newValue);
args.RoutedEvent = ColorPicker.SelectedColorChangedEvent;
RaiseEvent(args);
@ -80,6 +94,17 @@ namespace Microsoft.Windows.Controls
#endregion //SelectedColor
#region SelectedColorText
//public static readonly DependencyProperty SelectedColorTextProperty = DependencyProperty.Register("SelectedColorText", typeof(string), typeof(ColorPicker), new UIPropertyMetadata("Black"));
//public string SelectedColorText
//{
// get { return (string)GetValue(SelectedColorTextProperty); }
// protected set { SetValue(SelectedColorTextProperty, value); }
//}
#endregion //SelectedColorText
#region StandardColors
public static readonly DependencyProperty StandardColorsProperty = DependencyProperty.Register("StandardColors", typeof(ObservableCollection<ColorItem>), typeof(ColorPicker), new UIPropertyMetadata(CreateStandardColors()));
@ -103,6 +128,8 @@ namespace Microsoft.Windows.Controls
public ColorPicker()
{
RecentColors = new ObservableCollection<ColorItem>();
Keyboard.AddKeyDownHandler(this, OnKeyDown);
Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
}
#endregion //Constructors
@ -113,10 +140,10 @@ namespace Microsoft.Windows.Controls
{
base.OnApplyTemplate();
_colorPickerToggleButton = (ToggleButton)GetTemplateChild("PART_ColorPickerToggleButton");
_colorPickerToggleButton.Click += ColorPickerToggleButton_Clicked;
//_colorPickerToggleButton = (ToggleButton)GetTemplateChild("PART_ColorPickerToggleButton");
_colorPickerCanvasPopup = (Popup)GetTemplateChild("PART_ColorPickerPalettePopup");
_colorPickerCanvasPopup.Opened += ColorPickerCanvasPopup_Opened;
_availableColors = (ListBox)GetTemplateChild("PART_AvailableColors");
_availableColors.SelectionChanged += Color_SelectionChanged;
@ -132,9 +159,27 @@ namespace Microsoft.Windows.Controls
#region Event Handlers
void ColorPickerToggleButton_Clicked(object sender, RoutedEventArgs e)
void ColorPickerCanvasPopup_Opened(object sender, EventArgs e)
{
Mouse.Capture(this, CaptureMode.SubTree);
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Escape:
case Key.Tab:
{
CloseColorPicker();
break;
}
}
}
private void OnMouseDownOutsideCapturedElement(object sender, MouseButtonEventArgs e)
{
_colorPickerCanvasPopup.IsOpen = _colorPickerToggleButton.IsChecked ?? false;
CloseColorPicker();
}
private void Color_SelectionChanged(object sender, SelectionChangedEventArgs e)
@ -168,8 +213,9 @@ namespace Microsoft.Windows.Controls
private void CloseColorPicker()
{
_colorPickerToggleButton.IsChecked = false;
_colorPickerCanvasPopup.IsOpen = false;
if (IsOpen)
IsOpen = false;
ReleaseMouseCapture();
}
private void UpdateRecentColors(ColorItem colorItem)
@ -218,4 +264,4 @@ namespace Microsoft.Windows.Controls
#endregion //Methods
}
}
}

22
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs

@ -0,0 +1,22 @@
using System;
using System.Linq;
using System.Windows.Media;
using System.Reflection;
using System.Collections.Generic;
namespace Microsoft.Windows.Controls
{
static class ColorUtilities
{
public static string GetColorName(this Color color)
{
return _knownColors.Where(kvp => kvp.Value.Equals(color)).Select(kvp => kvp.Key).FirstOrDefault();
}
static readonly Dictionary<string, Color> _knownColors = GetKnownColors();
static Dictionary<string, Color> GetKnownColors()
{
var colorProperties = typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public);
return colorProperties.ToDictionary(p => p.Name, p => (Color)p.GetValue(null, null));
}
}
}

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

@ -261,7 +261,11 @@
<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" />
<Rectangle Grid.Row="1" Height="4" Margin="0,12,0,0">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=extToolkit:ColorPicker}}" />
</Rectangle.Fill>
</Rectangle>
</Grid>
<Path Grid.Column="1" Width="7" Height="4"

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

@ -8,13 +8,19 @@
<!-- =============================================================================== -->
<!-- Common Converters -->
<!-- =============================================================================== -->
<coreConverters:InverseBoolConverter x:Key="InverseBoolConverter" />
<!-- =============================================================================== -->
<!-- Common Styles -->
<!-- =============================================================================== -->
<SolidColorBrush x:Key="ButtonHover" Color="#C2E0FF"/>
<SolidColorBrush x:Key="ButtonHoverBorder" Color="#3399FF"/>
<SolidColorBrush x:Key="ButtonChecked" Color="#E6F0FA"/>
<SolidColorBrush x:Key="ButtonPressed" Color="#99CCFF"/>
<SolidColorBrush x:Key="ButtonPressedBorder" Color="#3399FF"/>
<LinearGradientBrush x:Key="WindowDarkBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AEB9" Offset="0"/>
<GradientStop Color="#FF8399A9" Offset="0.375"/>
@ -582,71 +588,6 @@
<GradientStop Color="#FF617584" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="ColorPickerToggleButton" TargetType="ToggleButton">
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="BorderThickness" Value="1,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="_backgroundHighlight" Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="_backgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="_backgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="_backgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border x:Name="Background" Background="White" BorderThickness="0" Grid.ColumnSpan="3" Cursor="Hand">
<Grid Margin="1" Background="#FF1F3B53">
<Border x:Name="_backgroundHighlight" Opacity="0" Background="#FF448DCA"/>
<Rectangle x:Name="_backgroundGradient">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#F3F3F3" Offset="0"/>
<GradientStop Color="#EBEBEB" Offset="0.5"/>
<GradientStop Color="#DDDDDD" Offset="0.5"/>
<GradientStop Color="#CDCDCD" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Border>
<Border Margin="5" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" BorderThickness="1" CornerRadius="3">
<Rectangle Fill="{TemplateBinding Background}" />
</Border>
<Border Grid.Column="1" Background="#FFC9CACA" BorderBrush="White" BorderThickness="1,0,0,0" Margin="0,2"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Grid.Column="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="PopupBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
@ -694,30 +635,79 @@
</Grid>
</DataTemplate>
<Style x:Key="ColorPickerToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" CornerRadius="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Grid x:Name="arrowGlyph" IsHitTestVisible="False" Grid.Column="1" Margin="5">
<Path 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>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ButtonHoverBorder}"/>
<Setter Property="Background" Value="{StaticResource ButtonChecked}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ButtonHoverBorder}"/>
<Setter Property="Background" Value="{StaticResource ButtonHover}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ButtonHoverBorder}"/>
<Setter Property="Background" Value="{StaticResource ButtonHover}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true"/>
<Condition Property="IsChecked" Value="true"/>
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="{StaticResource ButtonPressedBorder}"/>
<Setter Property="Background" Value="{StaticResource ButtonPressed}"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsKeyboardFocused" Value="true"/>
<Condition Property="IsChecked" Value="true"/>
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="{StaticResource ButtonPressedBorder}"/>
<Setter Property="Background" Value="{StaticResource ButtonPressed}"/>
</MultiTrigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ButtonPressedBorder}"/>
<Setter Property="Background" Value="{StaticResource ButtonPressed}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<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="ButtonStyle" Value="{StaticResource ColorPickerToggleButtonStyle}" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorPicker}">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0">
<Grid>
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{TemplateBinding ButtonStyle}" MinHeight="22">
<ToggleButton.Background>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</ToggleButton.Background>
<ToggleButton.Content>
<Grid x:Name="arrowGlyph" IsHitTestVisible="False">
<Path 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>
</ToggleButton.Content>
</ToggleButton>
</Grid>
</Border>
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{TemplateBinding ButtonStyle}" MinHeight="22" ClickMode="Press" IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}" >
<Border>
<Border.Background>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</Border.Background>
</Border>
</ToggleButton>
<Popup x:Name="PART_ColorPickerPalettePopup" VerticalAlignment="Bottom" IsOpen="False" >
<Popup x:Name="PART_ColorPickerPalettePopup" VerticalAlignment="Bottom" IsOpen="{Binding ElementName=PART_ColorPickerToggleButton, Path=IsChecked}" >
<Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" Padding="3">
<Grid Margin="4">
<Grid.RowDefinitions>
@ -988,7 +978,7 @@
<!-- =============================================================================== -->
<!-- DateTimeUpDown -->
<!-- =============================================================================== -->
<Style TargetType="{x:Type local:DateTimeUpDown}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Focusable" Value="False" />

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -74,6 +74,7 @@
<Compile Include="ButtonSpinner\ValidSpinDirections.cs" />
<Compile Include="ColorPicker\ColorItem.cs" />
<Compile Include="ColorPicker\ColorPicker.cs" />
<Compile Include="ColorPicker\ColorUtilities.cs" />
<Compile Include="Core\Converters\InverseBoolConverter.cs" />
<Compile Include="DateTimeUpDown\DateTimeFormat.cs" />
<Compile Include="DateTimeUpDown\DateTimeInfo.cs" />

Loading…
Cancel
Save