Browse Source

PropertyGrid: minor fixes, implemented TextBlockEditor for readonly properties.

pull/1645/head
brianlagunas_cp 16 years ago
parent
commit
26e89f796b
  1. 3
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CheckBoxEditor.cs
  2. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs
  3. 18
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/TextBlockEditor.cs
  4. 42
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  5. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml
  6. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

3
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CheckBoxEditor.cs

@ -8,8 +8,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
protected override void Initialize() protected override void Initialize()
{ {
Editor = new CheckBox(); Editor = new CheckBox();
Editor.Margin = new Thickness(4, 0, 0, 0); Editor.Margin = new Thickness(5, 0, 0, 0);
ValueProperty = CheckBox.IsCheckedProperty; ValueProperty = CheckBox.IsCheckedProperty;
} }
} }

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs

@ -7,6 +7,8 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
protected override void SetEditorProperties() protected override void SetEditorProperties()
{ {
NumericUpDown nud = (NumericUpDown)Editor; NumericUpDown nud = (NumericUpDown)Editor;
nud.Maximum = int.MaxValue;
nud.Minimum = int.MinValue;
nud.ValueType = typeof(int); nud.ValueType = typeof(int);
nud.FormatString = "F0"; nud.FormatString = "F0";
} }

18
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/TextBlockEditor.cs

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class TextBlockEditor : TypeEditor
{
protected override void Initialize()
{
Editor = new TextBlock();
(Editor as TextBlock).Margin = new System.Windows.Thickness(5, 0, 0, 0);
ValueProperty = TextBlock.TextProperty;
}
}
}

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

@ -52,8 +52,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
protected virtual void OnIsCategorizedChanged(bool oldValue, bool newValue) protected virtual void OnIsCategorizedChanged(bool oldValue, bool newValue)
{ {
LoadProperties(newValue); InitializePropertyGrid(newValue);
SetDragThumbMargin();
} }
#endregion //IsCategorized #endregion //IsCategorized
@ -104,8 +103,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
_propertyItemsCache = GetObjectProperties(newValue); _propertyItemsCache = GetObjectProperties(newValue);
LoadProperties(IsCategorized); InitializePropertyGrid(IsCategorized);
SetDragThumbMargin();
} }
#endregion //SelectedObject #endregion //SelectedObject
@ -146,13 +144,33 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region SelectedObjectName #region SelectedObjectName
public static readonly DependencyProperty SelectedObjectNameProperty = DependencyProperty.Register("SelectedObjectName", typeof(string), typeof(PropertyGrid), new UIPropertyMetadata(string.Empty)); public static readonly DependencyProperty SelectedObjectNameProperty = DependencyProperty.Register("SelectedObjectName", typeof(string), typeof(PropertyGrid), new UIPropertyMetadata(string.Empty, OnSelectedObjectNameChanged, OnCoerceSelectedObjectName));
public string SelectedObjectName public string SelectedObjectName
{ {
get { return (string)GetValue(SelectedObjectNameProperty); } get { return (string)GetValue(SelectedObjectNameProperty); }
private set { SetValue(SelectedObjectNameProperty, value); } private set { SetValue(SelectedObjectNameProperty, value); }
} }
private static object OnCoerceSelectedObjectName(DependencyObject o, object baseValue)
{
if (String.IsNullOrEmpty((String)baseValue))
return "<no name>";
return baseValue;
}
private static void OnSelectedObjectNameChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
PropertyGrid propertyGrid = o as PropertyGrid;
if (propertyGrid != null)
propertyGrid.SelectedObjectNameChanged((string)e.OldValue, (string)e.NewValue);
}
protected virtual void SelectedObjectNameChanged(string oldValue, string newValue)
{
}
#endregion //SelectedObjectName #endregion //SelectedObjectName
#region SelectedProperty #region SelectedProperty
@ -237,6 +255,12 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region Methods #region Methods
private void InitializePropertyGrid(bool isCategorized)
{
LoadProperties(isCategorized);
SetDragThumbMargin(isCategorized);
}
private void LoadProperties(bool isCategorized) private void LoadProperties(bool isCategorized)
{ {
if (isCategorized) if (isCategorized)
@ -294,7 +318,9 @@ namespace Microsoft.Windows.Controls.PropertyGrid
//no custom editor found //no custom editor found
if (editor == null) if (editor == null)
{ {
if (propertyItem.PropertyType == typeof(bool)) if (propertyItem.IsReadOnly)
editor = new TextBlockEditor();
else if (propertyItem.PropertyType == typeof(bool))
editor = new CheckBoxEditor(); editor = new CheckBoxEditor();
else if (propertyItem.PropertyType == typeof(int)) else if (propertyItem.PropertyType == typeof(int))
editor = new IntegerUpDownEditor(); editor = new IntegerUpDownEditor();
@ -367,12 +393,12 @@ namespace Microsoft.Windows.Controls.PropertyGrid
} }
} }
private void SetDragThumbMargin() private void SetDragThumbMargin(bool isCategorized)
{ {
if (_dragThumb == null) if (_dragThumb == null)
return; return;
if (IsCategorized) if (isCategorized)
_dragThumb.Margin = new Thickness(6, 0, 0, 0); _dragThumb.Margin = new Thickness(6, 0, 0, 0);
else else
_dragThumb.Margin = new Thickness(-1, 0, 0, 0); _dragThumb.Margin = new Thickness(-1, 0, 0, 0);

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

@ -305,9 +305,8 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="6,2,0,4"> <StackPanel Orientation="Horizontal" Margin="6,2,0,4">
<TextBlock Text="{TemplateBinding SelectedObjectTypeName}" FontWeight="Bold"/> <TextBlock Text="{TemplateBinding SelectedObjectTypeName}" FontWeight="Bold"/>
<TextBlock Width="6">:</TextBlock> <TextBlock Text="{TemplateBinding SelectedObjectName}" Margin="5,0,0,0" />
<TextBlock Text="{TemplateBinding SelectedObjectName}" />
</StackPanel> </StackPanel>
<Grid Grid.Row="1" Margin="4,0,4,4"> <Grid Grid.Row="1" Margin="4,0,4,4">

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

@ -179,6 +179,7 @@
<Compile Include="PropertyGrid\Implementation\Editors\IntegerUpDownEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\IntegerUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ITypeEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\ITypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\NumericUpDownEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\NumericUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TextBlockEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TextBoxEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\TextBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TypeEditor.cs" /> <Compile Include="PropertyGrid\Implementation\Editors\TypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" /> <Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" />

Loading…
Cancel
Save