Browse Source

PropertyGrid: implemented DateTimeUpDown type editor. Working on property binding options menu.

pull/1645/head
brianlagunas_cp 16 years ago
parent
commit
228975f121
  1. 13
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DateTimeUpDownEditor.cs
  2. 4
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  3. 39
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs
  4. 27
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml
  5. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

13
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DateTimeUpDownEditor.cs

@ -0,0 +1,13 @@
using System;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class DateTimeUpDownEditor : TypeEditor
{
protected override void Initialize()
{
Editor = new DateTimeUpDown();
ValueProperty = DateTimeUpDown.ValueProperty;
}
}
}

4
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs

@ -59,7 +59,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region NameWidth #region NameWidth
public static readonly DependencyProperty NameColumnWidthProperty = DependencyProperty.Register("NameColumnWidth", typeof(double), typeof(PropertyGrid), new UIPropertyMetadata(120.0)); public static readonly DependencyProperty NameColumnWidthProperty = DependencyProperty.Register("NameColumnWidth", typeof(double), typeof(PropertyGrid), new UIPropertyMetadata(150.0));
public double NameColumnWidth public double NameColumnWidth
{ {
get { return (double)GetValue(NameColumnWidthProperty); } get { return (double)GetValue(NameColumnWidthProperty); }
@ -287,6 +287,8 @@ namespace Microsoft.Windows.Controls.PropertyGrid
editor = new IntegerUpDownEditor(); editor = new IntegerUpDownEditor();
else if (propertyItem.PropertyType == typeof(double)) else if (propertyItem.PropertyType == typeof(double))
editor = new NumericUpDownEditor(); editor = new NumericUpDownEditor();
else if (propertyItem.PropertyType == typeof(DateTime))
editor = new DateTimeUpDownEditor();
else if (propertyItem.PropertyType.IsEnum) else if (propertyItem.PropertyType.IsEnum)
editor = new EnumComboBoxEditor(); editor = new EnumComboBoxEditor();
else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch)) else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))

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

@ -2,11 +2,18 @@
using System.Windows.Controls; using System.Windows.Controls;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using System.Windows.Data;
namespace Microsoft.Windows.Controls.PropertyGrid namespace Microsoft.Windows.Controls.PropertyGrid
{ {
public class PropertyItem : Control public class PropertyItem : Control
{ {
#region Members
private DependencyPropertyDescriptor _dpDescriptor;
#endregion //Members
#region Properties #region Properties
#region Category #region Category
@ -24,6 +31,21 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public object Instance { get; private set; } public object Instance { get; private set; }
/// <summary>
/// Gets if the property is data bound
/// </summary>
public bool IsDataBound
{
get
{
var dependencyObject = Instance as DependencyObject;
if (dependencyObject != null && _dpDescriptor != null)
return BindingOperations.GetBindingExpressionBase(dependencyObject, _dpDescriptor.DependencyProperty) != null;
return false;
}
}
public bool IsReadOnly { get { return PropertyDescriptor.IsReadOnly; } } public bool IsReadOnly { get { return PropertyDescriptor.IsReadOnly; } }
#region IsSelected #region IsSelected
@ -107,6 +129,21 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //Value #endregion //Value
/// <summary>
/// Gets the value source.
/// </summary>
public BaseValueSource ValueSource
{
get
{
var dependencyObject = Instance as DependencyObject;
if (_dpDescriptor != null && dependencyObject != null)
return DependencyPropertyHelper.GetValueSource(dependencyObject, _dpDescriptor.DependencyProperty).BaseValueSource;
return BaseValueSource.Unknown;
}
}
#endregion //Properties #endregion //Properties
#region Constructor #region Constructor
@ -123,6 +160,8 @@ namespace Microsoft.Windows.Controls.PropertyGrid
Name = PropertyDescriptor.Name; Name = PropertyDescriptor.Name;
Category = PropertyDescriptor.Category; Category = PropertyDescriptor.Category;
PropertyGrid = propertyGrid; PropertyGrid = propertyGrid;
_dpDescriptor = DependencyPropertyDescriptor.FromProperty(property);
} }
#endregion //Constructor #endregion //Constructor

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

@ -226,7 +226,22 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Name"> <Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Name">
<TextBlock Text="{Binding Name, RelativeSource={RelativeSource TemplatedParent}}" Margin="7,2,0,2"/> <Grid Margin="7,2,2,2">
<Grid.ColumnDefinitions>
<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>
</Grid>
</Border> </Border>
<Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Editor" Grid.Column="1" Background="Transparent"> <Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Editor" Grid.Column="1" Background="Transparent">
@ -235,6 +250,10 @@
</Grid> </Grid>
</Border> </Border>
<ControlTemplate.Triggers> <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>-->
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="PART_Name" Property="Background" Value="#CED4DF" /> <Setter TargetName="PART_Name" Property="Background" Value="#CED4DF" />
</Trigger> </Trigger>
@ -246,8 +265,8 @@
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type local:PropertyGrid}"> <Style TargetType="{x:Type local:PropertyGrid}">
<Setter Property="Background" Value="#CED4DF" /> <Setter Property="Background" Value="#CED4DF" />
<Setter Property="BorderBrush" Value="#43577B" /> <Setter Property="BorderBrush" Value="#43577B" />
@ -284,7 +303,7 @@
</RadioButton> </RadioButton>
<RadioButton IsChecked="{Binding IsCategorized, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}, Mode=OneWay}" VerticalAlignment="Center" <RadioButton IsChecked="{Binding IsCategorized, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}, Mode=OneWay}" VerticalAlignment="Center"
Style="{StaticResource OptionsToggleButtonStyle}" ToolTip="Alphabetical"> Style="{StaticResource OptionsToggleButtonStyle}" ToolTip="Alphabetical">
<Image Source="/WPFToolkit.Extended;component/PropertyGrid/Images/SortAscending16.png" Width="16" Height="16"/> <Image Source="/WPFToolkit.Extended;component/PropertyGrid/Images/SortAscending16.png" Width="16" Height="16"/>
</RadioButton> </RadioButton>
</StackPanel> </StackPanel>
</Grid> </Grid>

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

@ -169,6 +169,7 @@
<Compile Include="PropertyGrid\Implementation\Editors\ComboBoxEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\ComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CustomTypeEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\CustomTypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\CustomTypeEditorCollection.cs" /> <Compile Include="PropertyGrid\Implementation\CustomTypeEditorCollection.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\DateTimeUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\EnumComboBoxEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\EnumComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\FontComboBoxEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\FontComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ICustomTypeEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\ICustomTypeEditor.cs" />

Loading…
Cancel
Save