This project has moved. For the latest updates, please go here.

Propertygird - Extensions: Preview and Direct ObjectName Edit

Oct 20, 2012 at 7:29 AM

I've updatet the Propertygrid, to include a preview Window of WPF Controls and allowing the direct edit of the Name of the UIEelemnt 

Oct 20, 2012 at 7:31 AM

Looks like this: 

http://s1.directupload.net/file/d/3049/ipngrbu4_png.htm

Oct 20, 2012 at 7:32 AM

Index: Implementation/PropertyGrid.cs

===================================================================
--- Implementation/PropertyGrid.cs    (revision 95443)
+++ Implementation/PropertyGrid.cs    (working copy)
@@ -396,7 +396,7 @@
       {
         return ( string )GetValue( SelectedObjectNameProperty );
       }
-      private set
+      set
       {
         SetValue( SelectedObjectNameProperty, value );
       }
@@ -411,7 +411,10 @@
 
     protected virtual void SelectedObjectNameChanged( string oldValue, string newValue )
     {
-
+        if (SelectedObject is FrameworkElement)
+        {
+            ((FrameworkElement)SelectedObject).Name = newValue;            
+        }
     }
 
     #endregion //SelectedObjectName
@@ -468,6 +471,24 @@
 
     #endregion //ShowAdvancedOptions
 
+
+    #region ShowPreview
+
+    public static readonly DependencyProperty ShowPreviewProperty = DependencyProperty.Register("ShowPreview", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true));
+    public bool ShowPreview
+    {
+        get
+        {
+            return (bool)GetValue(ShowPreviewProperty);
+        }
+        set
+        {
+            SetValue(ShowPreviewProperty, value);
+        }
+    }
+
+    #endregion //ShowPreview
+
     #region ShowSearchBox
 
     public static readonly DependencyProperty ShowSearchBoxProperty = DependencyProperty.Register( "ShowSearchBox", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) );
Index: Themes/Generic.xaml
===================================================================
--- Themes/Generic.xaml    (revision 95443)
+++ Themes/Generic.xaml    (working copy)
@@ -362,7 +362,7 @@
                      </Border>
 
                      <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">
+                        <ItemsControl ScrollViewer.CanContentScroll="True" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False">
                            <ItemsControl.ItemsPanel>
                               <ItemsPanelTemplate>
                                  <VirtualizingStackPanel />
@@ -416,12 +416,26 @@
                         <RowDefinition Height="Auto"/>
                      </Grid.RowDefinitions>
 
-                     <StackPanel Orientation="Horizontal" Margin="6,2,0,4">
-                        <TextBlock Text="{TemplateBinding SelectedObjectTypeName}" FontWeight="Bold" Visibility="{Binding ShowTitle, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
-                        <TextBlock Text="{TemplateBinding SelectedObjectName}" Margin="5,0,0,0" Visibility="{Binding ShowTitle, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />
-                     </StackPanel>
+                            <DockPanel HorizontalAlignment="Stretch" Margin="2,2,0,4" LastChildFill="True">
+                                <Border DockPanel.Dock="Left" Background="White" DataContext="{TemplateBinding ShowPreview}" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Width="44" Height="44" HorizontalAlignment="Right" Margin="8 8 8 8" Padding="2">
+                                    <Border.Visibility>
+                                        <Binding>
+                                            <Binding.Converter>
+                                                <BooleanToVisibilityConverter />
+                                            </Binding.Converter>
+                                        </Binding>
+                                    </Border.Visibility>
+                                    <Rectangle>
+                                        <Rectangle.Fill>
+                                            <VisualBrush Stretch="Uniform" Visual="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedObject}"></VisualBrush>
+                                        </Rectangle.Fill>
+                                    </Rectangle>
+                                </Border>
+                                <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Height="{Binding Source={RelativeSource Self},Path=FontSize}" DockPanel.Dock="Left" Text="{TemplateBinding SelectedObjectTypeName}" FontWeight="Bold" Visibility="{Binding ShowTitle, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
+                                <local:WatermarkTextBox HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="{Binding Source={RelativeSource Self},Path=FontSize}" Watermark="&lt;No Name&gt;" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedObjectName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="5,0,5,0" Visibility="{Binding ShowTitle, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />                                
+                            </DockPanel>
 
-                     <Grid Grid.Row="1" Margin="4,0,4,4">
+                            <Grid Grid.Row="1" Margin="4,0,4,4">
                         <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
@@ -476,10 +490,16 @@
                         </Border>
                      </Grid>
 
-                     <Grid Grid.Row="2" Background="White">
-                        <ScrollViewer VerticalScrollBarVisibility="Auto">
-                           <ItemsControl ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False">
-                              <ItemsControl.ItemsPanel>
+                     <Grid Grid.Row="2" Background="White">                        
+                           <ItemsControl ScrollViewer.CanContentScroll="True" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False">
+                               <ItemsControl.Template>
+                                            <ControlTemplate>
+                                                <ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}">
+                                                    <ItemsPresenter />
+                                                </ScrollViewer>
+                                            </ControlTemplate>
+                                        </ItemsControl.Template>
+                               <ItemsControl.ItemsPanel>
                                  <ItemsPanelTemplate>
                                     <VirtualizingStackPanel />
                                  </ItemsPanelTemplate>
@@ -508,7 +528,6 @@
                               </ItemsControl.GroupStyle>
 
                            </ItemsControl>
-                        </ScrollViewer>
 
                          <Thumb x:Name="PART_DragThumb" HorizontalAlignment="Left" Width="5" Margin="6,0,0,0" Cursor="SizeWE">
                            <Thumb.Template>

Oct 20, 2012 at 7:34 AM

Hopefully this patch has the change to get into the main Source...