Browse Source

Fix to vertical column header

Kenric Nugteren 6 months ago
parent
commit
212ba14727

+ 0 - 17
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -698,16 +698,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                             {
                                 return new Image { Source = image };
                             }));
-                        // headStyle.AddSetter(GridHeaderCellControl.ContentProperty, image);
-                        // var template = new ControlTemplate(typeof(GridHeaderCellControl));
-                        // var border = new FrameworkElementFactory(typeof(Border));
-                        // border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
-                        // border.SetValue(Border.PaddingProperty, new Thickness(4));
-                        // // var img = new FrameworkElementFactory(typeof(Image));
-                        // // img.SetValue(Image.SourceProperty, image);
-                        // // border.AppendChild(img);
-                        // template.VisualTree = border;
-                        // headStyle.Setters.Add(new Setter(Control.TemplateProperty, template));
                     }
                 }
             }
@@ -716,13 +706,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                 headStyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
                 headStyle.Setters.Add(new Setter(Control.TemplateProperty,
                     Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
-                // headStyle.AddSetter(GridHeaderCellControl.ContentTemplateProperty,
-                //     TemplateGenerator.CreateDataTemplate(() =>
-                //     {
-                //         var content = new ContentPresenter();
-                //         content.SetBinding(ContentPresenter.ContentProperty, new Binding());
-                //         return content;
-                //     }));
             }
         }
         return headStyle;

+ 26 - 11
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -801,17 +801,24 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
                     var image = imgCol.Image?.Invoke(null);
                     if (image != null)
                     {
-                        var template = new ControlTemplate(typeof(TreeGridHeaderCell));
-                        var border = new FrameworkElementFactory(typeof(Border));
-                        border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
-                        border.SetValue(Border.PaddingProperty, new Thickness(4));
-                        border.Name = "PART_HeaderCellBorder";
-
-                        var img = new FrameworkElementFactory(typeof(Image));
-                        img.SetValue(Image.SourceProperty, image);
-                        border.AppendChild(img);
-                        template.VisualTree = border;
-                        headStyle.Setters.Add(new Setter(Control.TemplateProperty, template));
+                        // var template = new ControlTemplate(typeof(TreeGridHeaderCell));
+                        // var border = new FrameworkElementFactory(typeof(Border));
+                        // border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
+                        // border.SetValue(Border.PaddingProperty, new Thickness(4));
+                        // border.Name = "PART_HeaderCellBorder";
+
+                        // var img = new FrameworkElementFactory(typeof(Image));
+                        // img.SetValue(Image.SourceProperty, image);
+                        // border.AppendChild(img);
+                        // template.VisualTree = border;
+                        // headStyle.Setters.Add(new Setter(Control.TemplateProperty, template));
+
+                        headStyle.AddSetter(GridHeaderCellControl.PaddingProperty, new Thickness(4.0));
+                        headStyle.AddSetter(GridHeaderCellControl.ContentTemplateProperty,
+                            TemplateGenerator.CreateDataTemplate(() =>
+                            {
+                                return new Image { Source = image };
+                            }));
                     }
                 }
             }
@@ -1110,6 +1117,8 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
     {
         if (Parent.GetColumnFilter(column) is not IDynamicGridColumnFilter filter) return;
 
+        var vertical = column is DynamicActionColumn ac && ac.VerticalHeader && !ac.HeaderText.IsNullOrWhiteSpace();
+
         var horizontalAlignment = gridColumn.HorizontalHeaderContentAlignment;
         gridColumn.HorizontalHeaderContentAlignment = HorizontalAlignment.Stretch;
         gridColumn.HeaderTemplate = TemplateGenerator.CreateDataTemplate(() =>
@@ -1127,6 +1136,12 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
             var button = new DynamicGridColumnFilterUIButton(filter);
             grid.AddChild(button, 0, 1);
 
+            if(vertical)
+            {
+                button.LayoutTransform = new RotateTransform(90);
+                content.HorizontalAlignment = HorizontalAlignment.Stretch;
+            }
+
             return grid;
         });
     }

+ 2 - 4
inabox.wpf/Themes/Generic.xaml

@@ -537,10 +537,8 @@
                         ContentTemplate="{TemplateBinding ContentTemplate}"
                         ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False"
                         HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
-                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
-                        <ContentPresenter.Content>
-                            <TextBlock Text="{Binding HeaderText}" TextWrapping="Wrap" />
-                        </ContentPresenter.Content>
+                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
+                        Content="{TemplateBinding Content}">
                     </ContentPresenter>
                     <Grid x:Name="PART_SortButtonPresenter" Grid.Column="1" SnapsToDevicePixels="True">
                         <Grid.ColumnDefinitions>