Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This hasn't been an easy one but after some extensive googling and piecing up other people's experiences I've come up with this that work fine for me </p> <pre><code>string loadString = @"&lt;Style xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:localprimitives=""clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"" xmlns:vsm=""clr-namespace:System.Windows;assembly=System.Windows"" xmlns:data=""clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"" TargetType=""data:DataGridRowGroupHeader""&gt; &lt;Setter Property=""Cursor"" Value=""Arrow"" /&gt; &lt;Setter Property=""IsTabStop"" Value=""False"" /&gt; &lt;Setter Property=""Background"" Value=""#FFE4E8EA"" /&gt; &lt;Setter Property=""Height"" Value=""20""/&gt; &lt;Setter Property=""Template""&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType=""data:DataGridRowGroupHeader""&gt; &lt;localprimitives:DataGridFrozenGrid Name=""Root"" Background=""{TemplateBinding Background}""&gt; &lt;vsm:VisualStateManager.VisualStateGroups&gt; &lt;vsm:VisualStateGroup x:Name=""CurrentStates""&gt; &lt;vsm:VisualState x:Name=""Regular""/&gt; &lt;vsm:VisualState x:Name=""Current""&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetName=""FocusVisual"" Storyboard.TargetProperty=""Opacity"" To=""1"" Duration=""0"" /&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;/vsm:VisualStateManager.VisualStateGroups&gt; &lt;localprimitives:DataGridFrozenGrid.Resources&gt; &lt;/localprimitives:DataGridFrozenGrid.Resources&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width=""Auto"" /&gt; &lt;ColumnDefinition Width=""Auto"" /&gt; &lt;ColumnDefinition Width=""Auto"" /&gt; &lt;ColumnDefinition Width=""Auto"" /&gt; &lt;ColumnDefinition Width=""Auto"" /&gt; &lt;ColumnDefinition Width=""Auto"" /&gt;" </code></pre> <p>At this point I have some dynamic columns in the grid so I'm adding them just as the Grid.ColumnDefinitions so far but if your datagrid is static then you put the right number of columns. </p> <pre><code>+ colStr1 + @"&lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height=""Auto""/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition Height=""Auto""/&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel x:Name=""CustomRGHStackPanel"" Orientation=""Horizontal"" Tag=" + _tagNo + @" Grid.Column=""3"" Grid.Row=""1"" VerticalAlignment=""Center"" Margin=""0,1,0,1""&gt; &lt;StackPanel.Resources&gt; &lt;Style TargetType=""data:DataGridCell""&gt; &lt;Setter Property=""Background"" Value=""Transparent"" /&gt; &lt;Setter Property=""HorizontalContentAlignment"" Value=""Stretch"" /&gt; &lt;Setter Property=""VerticalContentAlignment"" Value=""Stretch"" /&gt; &lt;Setter Property=""IsTabStop"" Value=""False"" /&gt; &lt;Setter Property=""FontWeight"" Value=""Black""/&gt; &lt;Setter Property=""Template""&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType=""data:DataGridCell""&gt; &lt;Grid Margin=""1,-1,-1,0"" &gt; &lt;Grid Name=""Root"" Background=""{TemplateBinding Background}"" Margin=""5,0,0,0""&gt; &lt;vsm:VisualStateManager.VisualStateGroups&gt; &lt;vsm:VisualStateGroup x:Name=""CurrentStates""&gt; &lt;vsm:VisualState x:Name=""Regular"" /&gt; &lt;vsm:VisualState x:Name=""Current""&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetName=""FocusVisual"" Storyboard.TargetProperty=""Opacity"" To=""1"" Duration=""0"" /&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;vsm:VisualStateGroup x:Name=""ValidationStates""&gt; &lt;vsm:VisualState x:Name=""Valid""/&gt; &lt;vsm:VisualState x:Name=""Invalid""&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetName=""InvalidVisualElement"" Storyboard.TargetProperty=""Opacity"" Duration=""0"" To=""1""/&gt; &lt;ColorAnimation Storyboard.TargetName=""FocusVisual"" Storyboard.TargetProperty=""(Fill).Color"" Duration=""0"" To=""#FFFFFFFF""/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;/vsm:VisualStateManager.VisualStateGroups&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition Width=""Auto"" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Rectangle Name=""FocusVisual"" Stroke=""#FF6DBDD1"" StrokeThickness=""1"" Fill=""#66FFFFFF"" HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch"" IsHitTestVisible=""false"" Opacity=""0"" /&gt; &lt;ContentPresenter Content=""{TemplateBinding Content}"" ContentTemplate=""{TemplateBinding ContentTemplate}"" HorizontalAlignment=""{TemplateBinding HorizontalContentAlignment}"" VerticalAlignment=""{TemplateBinding VerticalContentAlignment}"" Margin=""{TemplateBinding Padding}"" /&gt; &lt;Rectangle x:Name=""InvalidVisualElement"" IsHitTestVisible=""False"" StrokeThickness=""1"" Stroke=""#FFDC000C"" HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch"" Opacity=""0""/&gt; &lt;Rectangle Name=""q1q"" Fill=""#c9caca"" Grid.Column=""1"" Margin=""1,0,1,0"" HorizontalAlignment=""Right"" VerticalAlignment=""Stretch"" Width=""0"" /&gt; &lt;/Grid&gt; &lt;Rectangle Name=""qq"" Fill=""#c9caca"" Margin=""1,0,1,0"" HorizontalAlignment=""Left"" VerticalAlignment=""Stretch"" Width=""1"" /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/StackPanel.Resources&gt; &lt;data:DataGridCell Content=""{Binding Name}""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell HorizontalContentAlignment=""Left"" Margin=""7,0,0,0"" Content=""{Binding Converter={StaticResource myConverter}, ConverterParameter=TotalScore}""/&gt;" + colStr2 + @"&lt;/StackPanel&gt; &lt;Rectangle Grid.Column=""1"" Grid.ColumnSpan=""5"" Fill=""#FFFFFFFF"" Height=""1""/&gt; &lt;Rectangle Grid.Column=""1"" Grid.Row=""1"" Name=""IndentSpacer"" /&gt; &lt;ToggleButton Grid.Column=""2"" Grid.Row=""1"" Name=""ExpanderButton"" Height=""15"" Width=""15"" Margin=""2,0,0,0""&gt; &lt;ToggleButton.Template&gt; &lt;ControlTemplate TargetType=""ToggleButton""&gt; &lt;Grid Background=""Transparent""&gt; &lt;vsm:VisualStateManager.VisualStateGroups&gt; &lt;vsm:VisualStateGroup x:Name=""CommonStates""&gt; &lt;vsm:VisualState x:Name=""Normal""/&gt; &lt;vsm:VisualState x:Name=""MouseOver""&gt; &lt;Storyboard&gt; &lt;ColorAnimation Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""(Stroke).Color"" Duration=""0"" To=""#FF6DBDD1""/&gt; &lt;ColorAnimation Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""(Fill).Color"" Duration=""0"" To=""#FF6DBDD1""/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;vsm:VisualState x:Name=""Pressed""&gt; &lt;Storyboard&gt; &lt;ColorAnimation Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""(Stroke).Color"" Duration=""0"" To=""#FF6DBDD1""/&gt; &lt;ColorAnimation Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""(Fill).Color"" Duration=""0"" To=""#FF6DBDD1""/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;vsm:VisualState x:Name=""Disabled""&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Duration=""0"" Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""Opacity"" To="".5""/&gt; &lt;DoubleAnimation Duration=""0"" Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""Opacity"" To="".5""/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;vsm:VisualStateGroup x:Name=""CheckStates""&gt; &lt;vsm:VisualState x:Name=""Checked"" /&gt; &lt;vsm:VisualState x:Name=""Unchecked""&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Duration=""0"" Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""Visibility""&gt; &lt;DiscreteObjectKeyFrame KeyTime=""0"" Value=""Visible""/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;ObjectAnimationUsingKeyFrames Duration=""0"" Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""Visibility""&gt; &lt;DiscreteObjectKeyFrame KeyTime=""0"" Value=""Collapsed""/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;/vsm:VisualStateManager.VisualStateGroups&gt; &lt;Path Stretch=""Uniform"" Data=""F1 M 0,0 L 0,1 L .6,.5 L 0,0 Z"" Width=""5"" HorizontalAlignment=""Center"" VerticalAlignment=""Center"" x:Name=""CollapsedArrow"" Visibility=""Collapsed"" Stroke=""#FF414345""/&gt; &lt;Path Stretch=""Uniform"" Data=""F1 M 0,1 L 1,1 L 1,0 L 0,1 Z"" Width=""6"" HorizontalAlignment=""Center"" VerticalAlignment=""Center"" x:Name=""ExpandedArrow"" Fill=""#FF414345""/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/ToggleButton.Template&gt; &lt;/ToggleButton&gt; &lt;Rectangle Grid.Column=""1"" Grid.ColumnSpan=""5"" Fill=""#FFD3D3D3"" Height=""1"" Grid.Row=""2""/&gt; &lt;Rectangle Name=""FocusVisual"" Grid.Column=""1"" Grid.ColumnSpan=""4"" Grid.RowSpan=""3"" Stroke=""#FF6DBDD1"" StrokeThickness=""1"" HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch"" IsHitTestVisible=""false"" Opacity=""0"" /&gt; &lt;localprimitives:DataGridRowHeader Name=""RowHeader"" Grid.RowSpan=""3"" localprimitives:DataGridFrozenGrid.IsFrozen=""True""/&gt; &lt;/localprimitives:DataGridFrozenGrid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt;"; </code></pre> <p>This is where your cell content comes in, and again I have some dynamic columns so I need to add cells dynamically (no need to do this if your grid is static) </p> <pre><code>&lt;data:DataGridCell Content=""{Binding Name}""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell Content=""""/&gt; &lt;data:DataGridCell HorizontalContentAlignment=""Left"" Margin=""7,0,0,0"" Content=""{Binding Converter={StaticResource myConverter}, ConverterParameter=TotalScore}""/&gt;" + colStr2 + </code></pre> <p>That is it pretty much, yes I agree it's not a trivial job but it gives you custom style when you need it! Feel free to comment!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload