Browse Source

PropertyGrid: fixed alignment of grid splitter for expanded properties

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
bdbd98b09e
  1. 20
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ExpandableObjectMarginConverter.cs
  2. 7
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs
  3. 25
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs
  4. 87
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml
  5. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

20
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ExpandableObjectMarginConverter.cs

@ -0,0 +1,20 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace Microsoft.Windows.Controls.Core.Converters
{
public class ExpandableObjectMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
int childLevel = (int)value;
return new Thickness(childLevel * 15, 0, 0, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

7
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs

@ -59,6 +59,13 @@ namespace Microsoft.Windows.Controls.PropertyGrid
return descriptors; return descriptors;
} }
internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath, int level)
{
PropertyItem item = CreatePropertyItem(property, instance, grid, bindingPath);
item.Level = level;
return item;
}
internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath) internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath)
{ {
PropertyItem propertyItem = new PropertyItem(instance, property, grid, bindingPath); PropertyItem propertyItem = new PropertyItem(instance, property, grid, bindingPath);

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

@ -1,13 +1,13 @@
using System; using System;
using System.Linq; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Windows.Controls.PropertyGrid.Commands;
using System.Windows.Markup.Primitives; using System.Windows.Markup.Primitives;
using System.Collections.Generic; using Microsoft.Windows.Controls.PropertyGrid.Commands;
namespace Microsoft.Windows.Controls.PropertyGrid namespace Microsoft.Windows.Controls.PropertyGrid
{ {
@ -187,9 +187,9 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region IsReadOnly #region IsReadOnly
public bool IsReadOnly public bool IsReadOnly
{ {
get { return PropertyDescriptor.IsReadOnly; } get { return PropertyDescriptor.IsReadOnly; }
} }
#endregion //IsReadOnly #endregion //IsReadOnly
@ -218,6 +218,17 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //IsSelected #endregion //IsSelected
#region Level
public static readonly DependencyProperty LevelProperty = DependencyProperty.Register("Level", typeof(int), typeof(PropertyItem), new UIPropertyMetadata(0));
public int Level
{
get { return (int)GetValue(LevelProperty); }
set { SetValue(LevelProperty, value); }
}
#endregion //Level
#region Properties #region Properties
public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(PropertyItemCollection), typeof(PropertyItem), new UIPropertyMetadata(null)); public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(PropertyItemCollection), typeof(PropertyItem), new UIPropertyMetadata(null));
@ -387,7 +398,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
foreach (PropertyDescriptor descriptor in descriptors) foreach (PropertyDescriptor descriptor in descriptors)
{ {
if (descriptor.IsBrowsable) if (descriptor.IsBrowsable)
propertyItems.Add(PropertyGridUtilities.CreatePropertyItem(descriptor, Instance, PropertyGrid, String.Format("{0}.{1}", BindingPath, descriptor.Name))); propertyItems.Add(PropertyGridUtilities.CreatePropertyItem(descriptor, Instance, PropertyGrid, String.Format("{0}.{1}", BindingPath, descriptor.Name), Level + 1));
} }
} }
catch (Exception ex) catch (Exception ex)

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

@ -13,6 +13,7 @@
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<converters:InverseBoolConverter x:Key="InverseBoolConverter" /> <converters:InverseBoolConverter x:Key="InverseBoolConverter" />
<converters:ExpandableObjectMarginConverter x:Key="ExpandableObjectMarginConverter" />
<pgConverters:ValueSourceToImagePathConverter x:Key="ValueSourceToImagePathConverter" /> <pgConverters:ValueSourceToImagePathConverter x:Key="ValueSourceToImagePathConverter" />
<pgConverters:ValueSourceToToolTipConverter x:Key="ValueSourceToToolTipConverter" /> <pgConverters:ValueSourceToToolTipConverter x:Key="ValueSourceToToolTipConverter" />
@ -299,20 +300,26 @@
<Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Name"> <Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Name">
<Grid Margin="2,2,2,2"> <Grid Margin="2,2,2,2">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="15" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border Grid.Column="0" > <Grid Margin="{Binding Level, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ExpandableObjectMarginConverter}}">
<ToggleButton Template="{StaticResource ExpanderToggleButton}" OverridesDefaultStyle="True" <Grid.ColumnDefinitions>
<ColumnDefinition Width="15" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" >
<ToggleButton Template="{StaticResource ExpanderToggleButton}" OverridesDefaultStyle="True"
IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
Visibility="{Binding HasChildProperties, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/> Visibility="{Binding HasChildProperties, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Border> </Border>
<TextBlock Grid.Column="1" Text="{Binding DisplayName, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"/> <TextBlock Grid.Column="1" Text="{Binding DisplayName, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"/>
</Grid>
<Grid Grid.Column="2" HorizontalAlignment="Right" Margin="5,0,5,0" Visibility="{Binding ShowAdvancedOptions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}, Converter={StaticResource BooleanToVisibilityConverter}}" <Grid Grid.Column="1" HorizontalAlignment="Right" Margin="5,0,5,0" Visibility="{Binding ShowAdvancedOptions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}, Converter={StaticResource BooleanToVisibilityConverter}}"
utilities:ContextMenuUtilities.OpenOnMouseLeftButtonClick="True" utilities:ContextMenuUtilities.OpenOnMouseLeftButtonClick="True"
ContextMenu="{Binding AdvancedOptionsMenu, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}}" > ContextMenu="{Binding AdvancedOptionsMenu, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}}" >
@ -328,7 +335,7 @@
</Border> </Border>
<Expander x:Name="_propertyExpander" Grid.ColumnSpan="2" Grid.Row="1" IsExpanded="{TemplateBinding IsExpanded}" Style="{StaticResource PropertyExpanderStyle}" IsEnabled="True"> <Expander x:Name="_propertyExpander" Grid.ColumnSpan="2" Grid.Row="1" IsExpanded="{TemplateBinding IsExpanded}" Style="{StaticResource PropertyExpanderStyle}" IsEnabled="True">
<ItemsControl ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False" Margin="15,0,0,0" > <ItemsControl ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False" >
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<VirtualizingStackPanel /> <VirtualizingStackPanel />
@ -364,72 +371,6 @@
</Setter> </Setter>
</Style> </Style>
<!--<Style TargetType="{x:Type local:PropertyItem}">
<Setter Property="BorderBrush" Value="#FFF0F0F0" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Focusable" Value="True"/>
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PropertyItem}">
<Border Background="White" ContextMenu="{Binding AdvancedOptionsMenu, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}}" ContextMenuService.Placement="Bottom">
<Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding NameColumnWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PropertyGrid}}}"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Name">
<Grid Margin="7,2,2,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding DisplayName, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"/>
<Grid Grid.Column="1" HorizontalAlignment="Right" Margin="5,0,5,0" Visibility="{Binding ShowAdvancedOptions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}, Converter={StaticResource BooleanToVisibilityConverter}}"
utilities:ContextMenuUtilities.OpenOnMouseLeftButtonClick="True"
ContextMenu="{Binding AdvancedOptionsMenu, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:PropertyGrid}}" >
<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>
<Border BorderThickness="0.5" BorderBrush="#FFF0F0F0" x:Name="PART_Editor" Grid.Column="1" Background="Transparent">
<ContentControl Content="{TemplateBinding Editor}" VerticalAlignment="Center" Focusable="False" IsTabStop="False" />
</Border>
</Grid>
</Border>
<ControlTemplate.Triggers>
<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>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="PART_Name" Property="Background" Value="#43577B" />
<Setter TargetName="PART_Name" Property="TextElement.Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>-->
<Style TargetType="{x:Type local:PropertyGrid}"> <Style TargetType="{x:Type local:PropertyGrid}">
<Setter Property="AdvancedOptionsMenu" Value="{StaticResource DefaultAdvancedOptionsMenu}" /> <Setter Property="AdvancedOptionsMenu" Value="{StaticResource DefaultAdvancedOptionsMenu}" />
<Setter Property="Background" Value="#CED4DF" /> <Setter Property="Background" Value="#CED4DF" />

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

@ -267,6 +267,7 @@
<Compile Include="PropertyGrid\Implementation\Editors\TextBlockEditor.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="Core\Converters\ExpandableObjectMarginConverter.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" /> <Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItemCollection.cs" /> <Compile Include="PropertyGrid\Implementation\PropertyItemCollection.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItem.cs" /> <Compile Include="PropertyGrid\Implementation\PropertyItem.cs" />

Loading…
Cancel
Save