Browse Source

PropertyGrid: Working on property options, and ValueSource icons.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
85bfc4484f
  1. 35
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Utilities/ContextMenuUtilities.cs
  2. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/AdvancedProperties11.png
  3. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Database11.png
  4. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Inheritance11.png
  5. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Local11.png
  6. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Resource11.png
  7. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Style11.png
  8. 17
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Commands/PropertyItemCommands.cs
  9. 48
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Converters/ValueSourceToImagePathConverter.cs
  10. 42
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Converters/ValueSourceToToolTipConverter.cs
  11. 153
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs
  12. 51
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml
  13. 18
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

35
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Utilities/ContextMenuUtilities.cs

@ -0,0 +1,35 @@
using System;
using System.Windows;
namespace Microsoft.Windows.Controls.Core.Utilities
{
public class ContextMenuUtilities
{
public static readonly DependencyProperty OpenOnMouseLeftButtonClickProperty = DependencyProperty.RegisterAttached("OpenOnMouseLeftButtonClick", typeof(bool), typeof(FrameworkElement), new FrameworkPropertyMetadata(false, OpenOnMouseLeftButtonClickChanged));
public static void SetOpenOnMouseLeftButtonClick(FrameworkElement element, bool value)
{
element.SetValue(OpenOnMouseLeftButtonClickProperty, value);
}
public static bool GetOpenOnMouseLeftButtonClick(FrameworkElement element)
{
return (bool)element.GetValue(OpenOnMouseLeftButtonClickProperty);
}
public static void OpenOnMouseLeftButtonClickChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var control = (FrameworkElement)sender;
if ((bool)e.NewValue)
{
control.PreviewMouseLeftButtonDown += (s, args) =>
{
if (control.ContextMenu != null)
{
control.ContextMenu.PlacementTarget = control;
control.ContextMenu.IsOpen = true;
}
};
}
//TODO: remove handler when set to false
}
}
}

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/AdvancedProperties11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Database11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Inheritance11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Local11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Resource11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Images/Style11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

17
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Commands/PropertyItemCommands.cs

@ -0,0 +1,17 @@
using System;
using System.Windows.Input;
namespace Microsoft.Windows.Controls.PropertyGrid.Commands
{
public static class PropertyItemCommands
{
private static RoutedCommand _resetValueCommand = new RoutedCommand();
public static RoutedCommand ResetValue
{
get
{
return _resetValueCommand;
}
}
}
}

48
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Converters/ValueSourceToImagePathConverter.cs

@ -0,0 +1,48 @@
using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace Microsoft.Windows.Controls.PropertyGrid.Converters
{
public class ValueSourceToImagePathConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
BaseValueSource bvs = (BaseValueSource)value;
string uriPrefix = "/WPFToolkit.Extended;component/PropertyGrid/Images/";
string imageName = "AdvancedProperties11";
switch (bvs)
{
case BaseValueSource.Inherited:
case BaseValueSource.DefaultStyle:
case BaseValueSource.ImplicitStyleReference:
imageName = "Inheritance11";
break;
case BaseValueSource.DefaultStyleTrigger:
break;
case BaseValueSource.Style:
imageName = "Style11";
break;
case BaseValueSource.Local:
imageName = "Local11";
break;
}
return new BitmapImage(new Uri(String.Format("{0}{1}.png", uriPrefix, imageName), UriKind.RelativeOrAbsolute));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}

42
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Converters/ValueSourceToToolTipConverter.cs

@ -0,0 +1,42 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace Microsoft.Windows.Controls.PropertyGrid.Converters
{
class ValueSourceToToolTipConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
BaseValueSource bvs = (BaseValueSource)value;
string toolTip = "Advanced Properties";
switch (bvs)
{
case BaseValueSource.Inherited:
case BaseValueSource.DefaultStyle:
case BaseValueSource.ImplicitStyleReference:
toolTip = "Inheritance";
break;
case BaseValueSource.Style:
toolTip = "Style Setter";
break;
case BaseValueSource.Local:
toolTip = "Local";
break;
}
return toolTip;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}

153
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs

@ -1,8 +1,12 @@
using System;
using System.Windows.Controls;
using System.Linq;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using Microsoft.Windows.Controls.PropertyGrid.Commands;
using System.Windows.Markup.Primitives;
namespace Microsoft.Windows.Controls.PropertyGrid
{
@ -11,6 +15,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region Members
private DependencyPropertyDescriptor _dpDescriptor;
private MarkupObject _markupObject;
#endregion //Members
@ -29,7 +34,30 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public string Description { get { return PropertyDescriptor.Description; } }
public object Instance { get; private set; }
#region Editor
public static readonly DependencyProperty EditorProperty = DependencyProperty.Register("Editor", typeof(FrameworkElement), typeof(PropertyItem), new UIPropertyMetadata(null));
public FrameworkElement Editor
{
get { return (FrameworkElement)GetValue(EditorProperty); }
set { SetValue(EditorProperty, value); }
}
#endregion //Editor
private object _instance;
public object Instance
{
get
{
return _instance;
}
private set
{
_instance = value;
_markupObject = MarkupWriter.GetMarkupObjectFor(_instance);
}
}
/// <summary>
/// Gets if the property is data bound
@ -46,6 +74,30 @@ namespace Microsoft.Windows.Controls.PropertyGrid
}
}
public bool IsDynamicResource
{
get
{
var markupProperty = _markupObject.Properties.Where(p => p.Name == PropertyDescriptor.Name).FirstOrDefault();
if (markupProperty != null)
return markupProperty.Value is DynamicResourceExtension;
return false;
}
}
public bool HasResourceApplied
{
//TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style
get
{
var markupProperty = _markupObject.Properties.Where(p => p.Name == PropertyDescriptor.Name).FirstOrDefault();
if (markupProperty != null)
return markupProperty.Value is Style;
return false;
}
}
public bool IsReadOnly { get { return PropertyDescriptor.IsReadOnly; } }
#region IsSelected
@ -74,41 +126,37 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public bool IsWriteable { get { return !IsReadOnly; } }
public PropertyDescriptor PropertyDescriptor { get; private set; }
private PropertyDescriptor _propertyDescriptor;
public PropertyDescriptor PropertyDescriptor
{
get
{
return _propertyDescriptor;
}
private set
{
_propertyDescriptor = value;
Name = _propertyDescriptor.Name;
Category = _propertyDescriptor.Category;
_dpDescriptor = DependencyPropertyDescriptor.FromProperty(_propertyDescriptor);
}
}
public PropertyGrid PropertyGrid { get; private set; }
public Type PropertyType { get { return PropertyDescriptor.PropertyType; } }
#region Editor
public static readonly DependencyProperty EditorProperty = DependencyProperty.Register("Editor", typeof(FrameworkElement), typeof(PropertyItem), new UIPropertyMetadata(null));
public FrameworkElement Editor
{
get { return (FrameworkElement)GetValue(EditorProperty); }
set { SetValue(EditorProperty, value); }
}
#endregion //Editor
public ICommand ResetValueCommand { get; private set; }
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(PropertyItem), new UIPropertyMetadata(null, new PropertyChangedCallback(OnValueChanged), new CoerceValueCallback(OnCoerceValue)));
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(PropertyItem), new UIPropertyMetadata(null, OnValueChanged));
public object Value
{
get { return (object)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private static object OnCoerceValue(DependencyObject o, object value)
{
PropertyItem propertyItem = o as PropertyItem;
if (propertyItem != null)
return propertyItem.OnCoerceValue((object)value);
else
return value;
}
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
PropertyItem propertyItem = o as PropertyItem;
@ -116,16 +164,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid
propertyItem.OnValueChanged((object)e.OldValue, (object)e.NewValue);
}
protected virtual object OnCoerceValue(object value)
{
// TODO: Keep the proposed value within the desired range.
return value;
}
protected virtual void OnValueChanged(object oldValue, object newValue)
{
// TODO: Add your property changed side-effects. Descendants can override as well.
}
}
#endregion //Value
@ -155,29 +197,62 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public PropertyItem(object instance, PropertyDescriptor property, PropertyGrid propertyGrid)
{
Instance = instance;
PropertyDescriptor = property;
Name = PropertyDescriptor.Name;
Category = PropertyDescriptor.Category;
PropertyGrid = propertyGrid;
Instance = instance;
_dpDescriptor = DependencyPropertyDescriptor.FromProperty(property);
CommandBindings.Add(new CommandBinding(PropertyItemCommands.ResetValue, ExecuteResetValueCommand, CanExecuteResetValueCommand));
AddHandler(Mouse.MouseDownEvent, new MouseButtonEventHandler(PropertyItem_MouseDown), true);
AddHandler(Mouse.PreviewMouseDownEvent, new MouseButtonEventHandler(PropertyItem_PreviewMouseDown), true);
}
#endregion //Constructor
#region Base Class Overrides
#region Event Handlers
protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
void PropertyItem_MouseDown(object sender, MouseButtonEventArgs e)
{
IsSelected = true;
if (Editor != null)
Editor.Focus();
e.Handled = true;
}
#endregion //Base Class Overrides
void PropertyItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
IsSelected = true;
//if it is a comboBox then the selection will not take when Focus is called
if (!(e.Source is ComboBox))
Focus();
}
#endregion //Event Handlers
#region Commands
private void ExecuteResetValueCommand(object sender, ExecutedRoutedEventArgs e)
{
if (PropertyDescriptor.CanResetValue(Instance))
PropertyDescriptor.ResetValue(Instance);
//TODO: notify UI that the ValueSource may have changed to update the icon
}
private void CanExecuteResetValueCommand(object sender, CanExecuteRoutedEventArgs e)
{
bool canExecute = false;
if (PropertyDescriptor.CanResetValue(Instance) && !PropertyDescriptor.IsReadOnly)
{
canExecute = true;
}
e.CanExecute = canExecute;
}
#endregion //Commands
}
}

51
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml

@ -1,13 +1,18 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Microsoft.Windows.Controls.PropertyGrid"
xmlns:converters="clr-namespace:Microsoft.Windows.Controls.Core.Converters">
xmlns:converters="clr-namespace:Microsoft.Windows.Controls.Core.Converters"
xmlns:pgConverters="clr-namespace:Microsoft.Windows.Controls.PropertyGrid.Converters"
xmlns:utilities="clr-namespace:Microsoft.Windows.Controls.Core.Utilities"
xmlns:commands="clr-namespace:Microsoft.Windows.Controls.PropertyGrid.Commands">
<!-- =============================================================================== -->
<!-- PropertyGrid -->
<!-- =============================================================================== -->
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
<pgConverters:ValueSourceToImagePathConverter x:Key="ValueSourceToImagePathConverter" />
<pgConverters:ValueSourceToToolTipConverter x:Key="ValueSourceToToolTipConverter" />
<SolidColorBrush x:Key="MouseOverBorderBrush" Color="#FFFFB700" />
<LinearGradientBrush x:Key="MouseOverBackgroundBrush" StartPoint="0,0" EndPoint="0,1" >
@ -213,12 +218,17 @@
<Style TargetType="{x:Type local:PropertyItem}">
<Setter Property="BorderBrush" Value="#FFF0F0F0" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Focusable" Value="False"/>
<Setter Property="Focusable" Value="True"/>
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PropertyItem}">
<Border>
<ControlTemplate.Resources>
<ContextMenu x:Key="ContextMenu">
<MenuItem Header="Reset Value" Command="commands:PropertyItemCommands.ResetValue" />
</ContextMenu>
</ControlTemplate.Resources>
<Border Background="White" ContextMenu="{StaticResource ContextMenu}" ContextMenuService.Placement="Bottom">
<Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding NameColumnWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PropertyGrid}}}"/>
@ -231,16 +241,17 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"/>
<Border x:Name="Options" Grid.Column="1" HorizontalAlignment="Right" Margin="5,0,5,0" Height="8" Width="8"
Background="Black" Visibility="Collapsed" ToolTip="{Binding ValueSource, RelativeSource={RelativeSource TemplatedParent}}">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Reset Value" />
</ContextMenu>
</Border.ContextMenu>
</Border>
<TextBlock Text="{Binding Name, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"/>
<Grid Grid.Column="1" HorizontalAlignment="Right" Margin="5,0,5,0"
utilities:ContextMenuUtilities.OpenOnMouseLeftButtonClick="True"
ContextMenu="{StaticResource ContextMenu}" >
<Image x:Name="_optionsImage" Width="11" Height="11"
Source="{Binding ValueSource, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ValueSourceToImagePathConverter}}"
ToolTip="{Binding ValueSource, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ValueSourceToToolTipConverter}}" />
</Grid>
</Grid>
</Border>
@ -250,10 +261,18 @@
</Grid>
</Border>
<ControlTemplate.Triggers>
<!--<DataTrigger Binding="{Binding IsDataBound, RelativeSource={RelativeSource Self}}" Value="True">
<Setter TargetName="Options" Property="Background" Value="Red"/>
<Setter TargetName="Options" Property="ToolTip" Value="Databinding"/>
</DataTrigger>-->
<DataTrigger Binding="{Binding IsDataBound, RelativeSource={RelativeSource Self}}" Value="True">
<Setter TargetName="_optionsImage" Property="Source" Value="/WPFToolkit.Extended;component/PropertyGrid/Images/Database11.png" />
<Setter TargetName="_optionsImage" Property="ToolTip" Value="Databinding" />
</DataTrigger>
<DataTrigger Binding="{Binding IsDynamicResource, RelativeSource={RelativeSource Self}}" Value="True">
<Setter TargetName="_optionsImage" Property="Source" Value="/WPFToolkit.Extended;component/PropertyGrid/Images/Resource11.png" />
<Setter TargetName="_optionsImage" Property="ToolTip" Value="Resource" />
</DataTrigger>
<DataTrigger Binding="{Binding HasResourceApplied, RelativeSource={RelativeSource Self}}" Value="True">
<Setter TargetName="_optionsImage" Property="Source" Value="/WPFToolkit.Extended;component/PropertyGrid/Images/Resource11.png" />
<Setter TargetName="_optionsImage" Property="ToolTip" Value="Resource" />
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="PART_Name" Property="Background" Value="#CED4DF" />
</Trigger>

18
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -137,6 +137,7 @@
<Compile Include="ColorPicker\Implementation\ColorUtilities.cs" />
<Compile Include="Core\Converters\ColorToSolidColorBrushConverter.cs" />
<Compile Include="Core\Converters\InverseBoolConverter.cs" />
<Compile Include="Core\Utilities\ContextMenuUtilities.cs" />
<Compile Include="DateTimeUpDown\Implementation\DateTimeFormat.cs" />
<Compile Include="DateTimeUpDown\Implementation\DateTimeInfo.cs" />
<Compile Include="DateTimeUpDown\Implementation\DateTimePart.cs" />
@ -164,6 +165,8 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="BusyIndicator\Implementation\VisualStates.BusyIndicator.cs" />
<Compile Include="PropertyGrid\Implementation\Converters\ValueSourceToImagePathConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Converters\ValueSourceToToolTipConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CheckBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ColorEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ComboBoxEditor.cs" />
@ -182,6 +185,7 @@
<Compile Include="PropertyGrid\Implementation\PropertyCategoryItem.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyCollection.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItem.cs" />
<Compile Include="PropertyGrid\Implementation\Commands\PropertyItemCommands.cs" />
<Compile Include="RichTextBoxFormatBar\IRichTextBoxFormatBar.cs" />
<Compile Include="RichTextBoxFormatBar\RichTextBoxFormatBar.xaml.cs">
<DependentUpon>RichTextBoxFormatBar.xaml</DependentUpon>
@ -251,6 +255,20 @@
<ItemGroup>
<Resource Include="PropertyGrid\Images\Categorize16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="PropertyGrid\Images\AdvancedProperties11.png" />
<Resource Include="PropertyGrid\Images\Inheritance11.png" />
<Resource Include="PropertyGrid\Images\Resource11.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="PropertyGrid\Images\Database11.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="PropertyGrid\Images\Local11.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="PropertyGrid\Images\Style11.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.

Loading…
Cancel
Save