Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Either of the other solutions work - but they both cause a scrolling problem.</p> <p>If you have a DataGrid that does not have RowHeight set, then the row height will be determined by the size of these TextBlocks. Well, the DataGrid uses virtualization and doesn't draw the TextBlocks until they are displayed. So it simply does not know how big the scrollbar should be. Scrolling with the middle mouse button then causes all sorts of unfortunate behavior.</p> <p>I'm using paging on my datagrid so I'm disabling virtualization by setting the DataGrid's Style to this:</p> <pre><code>xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data" xmlns:SystemWindowsControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"&gt; &lt;UserControl.Resources&gt; &lt;Style x:Key="DataGridStyleNoVirtualization" TargetType="SystemWindowsControls:DataGrid"&gt; &lt;Setter Property="RowBackground" Value="#AAEAEFF4" /&gt; &lt;Setter Property="AlternatingRowBackground" Value="#00FFFFFF" /&gt; &lt;Setter Property="Background" Value="#FFFFFFFF" /&gt; &lt;Setter Property="HeadersVisibility" Value="Column" /&gt; &lt;Setter Property="HorizontalScrollBarVisibility" Value="Auto" /&gt; &lt;Setter Property="VerticalScrollBarVisibility" Value="Auto" /&gt; &lt;Setter Property="SelectionMode" Value="Extended" /&gt; &lt;Setter Property="CanUserReorderColumns" Value="True" /&gt; &lt;Setter Property="CanUserResizeColumns" Value="True" /&gt; &lt;Setter Property="CanUserSortColumns" Value="True" /&gt; &lt;Setter Property="AutoGenerateColumns" Value="True" /&gt; &lt;Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" /&gt; &lt;Setter Property="BorderBrush"&gt; &lt;Setter.Value&gt; &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#FFA3AEB9" Offset="0"/&gt; &lt;GradientStop Color="#FF8399A9" Offset="0.375"/&gt; &lt;GradientStop Color="#FF718597" Offset="0.375"/&gt; &lt;GradientStop Color="#FF617584" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="BorderThickness" Value="1" /&gt; &lt;Setter Property="DragIndicatorStyle"&gt; &lt;Setter.Value&gt; &lt;!-- TODO: Change the TargetType to Control when the fix Jolt bugs 18719 is verified --&gt; &lt;Style TargetType="ContentControl"&gt; &lt;Setter Property="Foreground" Value="#7FFFFFFF" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;!-- TODO: Change the TargetType to Control when the fix Jolt bugs 18719 is verified --&gt; &lt;ControlTemplate TargetType="ContentControl"&gt; &lt;Grid&gt; &lt;vsm:VisualStateManager.VisualStateGroups&gt; &lt;vsm:VisualStateGroup x:Name="SortStates"&gt; &lt;vsm:VisualState x:Name="Unsorted" /&gt; &lt;vsm:VisualState x:Name="SortAscending"&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0"/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;vsm:VisualState x:Name="SortDescending"&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0"/&gt; &lt;DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="(RenderTransform).ScaleY" Duration="0" To="-.9"/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;/vsm:VisualStateManager.VisualStateGroups&gt; &lt;Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Fill="#66808080" Grid.ColumnSpan="2" /&gt; &lt;Rectangle x:Name="BackgroundGradient" Stretch="Fill" Grid.ColumnSpan="2" Opacity="0" &gt; &lt;Rectangle.Fill&gt; &lt;LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"&gt; &lt;GradientStop Color="#FFFFFFFF" Offset="0.015" /&gt; &lt;GradientStop Color="#F9FFFFFF" Offset="0.375" /&gt; &lt;GradientStop Color="#E5FFFFFF" Offset="0.6" /&gt; &lt;GradientStop Color="#C6FFFFFF" Offset="1" /&gt; &lt;/LinearGradientBrush&gt; &lt;/Rectangle.Fill&gt; &lt;/Rectangle&gt; &lt;Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ContentPresenter Content="{TemplateBinding Content}"/&gt; &lt;Path Grid.Column="1" Name="SortIcon" Fill="#7FFFFFFF" RenderTransformOrigin=".5,.5" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0" Stretch="Uniform" Width="8" Margin="4,0,0,0" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z "&gt; &lt;Path.RenderTransform&gt; &lt;ScaleTransform ScaleX=".9" ScaleY=".9" /&gt; &lt;/Path.RenderTransform&gt; &lt;/Path&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="DropLocationIndicatorStyle"&gt; &lt;Setter.Value&gt; &lt;Style TargetType="ContentControl"&gt; &lt;Setter Property="Background" Value="#FF3F4346"/&gt; &lt;Setter Property="Width" Value="2"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ContentControl"&gt; &lt;Rectangle Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"/&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="GridLinesVisibility" Value="Vertical" /&gt; &lt;Setter Property="HorizontalGridLinesBrush" Value="#FFC9CACA" /&gt; &lt;Setter Property="IsTabStop" Value="True" /&gt; &lt;Setter Property="VerticalGridLinesBrush" Value="#FFC9CACA" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="SystemWindowsControls:DataGrid"&gt; &lt;Grid&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="Disabled"&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/&gt; &lt;/Storyboard&gt; &lt;/vsm:VisualState&gt; &lt;/vsm:VisualStateGroup&gt; &lt;/vsm:VisualStateManager.VisualStateGroups&gt; &lt;Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="2"&gt; &lt;Grid Name="Root" Background="{TemplateBinding Background}"&gt; &lt;Grid.Resources&gt; &lt;!--Start: TopLeftHeaderTemplate--&gt; &lt;ControlTemplate x:Key="TopLeftHeaderTemplate" TargetType="dataprimitives:DataGridColumnHeader"&gt; &lt;Grid Name="Root"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Border BorderThickness="0,0,1,0" BorderBrush="#FFC9CACA" Background="#FF1F3B53" Grid.RowSpan="2"&gt; &lt;Rectangle Stretch="Fill" StrokeThickness="1"&gt; &lt;Rectangle.Fill&gt; &lt;LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"&gt; &lt;GradientStop Color="#FCFFFFFF" Offset="0.015" /&gt; &lt;GradientStop Color="#F7FFFFFF" Offset="0.375" /&gt; &lt;GradientStop Color="#E5FFFFFF" Offset="0.6" /&gt; &lt;GradientStop Color="#D1FFFFFF" Offset="1" /&gt; &lt;/LinearGradientBrush&gt; &lt;/Rectangle.Fill&gt; &lt;/Rectangle&gt; &lt;/Border&gt; &lt;Rectangle VerticalAlignment="Bottom" Width="Auto" StrokeThickness="1" Height="1" Fill="#FFDBDCDC" Grid.RowSpan="2"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;!--End: TopLeftHeaderTemplate--&gt; &lt;!--Start: TopRightHeaderTemplate--&gt; &lt;ControlTemplate x:Key="TopRightHeaderTemplate" TargetType="dataprimitives:DataGridColumnHeader"&gt; &lt;Grid Name="RootElement"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Border BorderThickness="1,0,0,0" BorderBrush="#FFC9CACA" Background="#FF1F3B53" Grid.RowSpan="2"&gt; &lt;Rectangle Stretch="Fill"&gt; &lt;Rectangle.Fill&gt; &lt;LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"&gt; &lt;GradientStop Color="#FCFFFFFF" Offset="0.015" /&gt; &lt;GradientStop Color="#F7FFFFFF" Offset="0.375" /&gt; &lt;GradientStop Color="#E5FFFFFF" Offset="0.6" /&gt; &lt;GradientStop Color="#D1FFFFFF" Offset="1" /&gt; &lt;/LinearGradientBrush&gt; &lt;/Rectangle.Fill&gt; &lt;/Rectangle&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;!--End: TopRightHeaderTemplate--&gt; &lt;/Grid.Resources&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition/&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;dataprimitives:DataGridColumnHeader Name="TopLeftCornerHeader" Template="{StaticResource TopLeftHeaderTemplate}" Width="22" /&gt; &lt;dataprimitives:DataGridColumnHeadersPresenter Name="ColumnHeadersPresenter" Grid.Column="1"/&gt; &lt;dataprimitives:DataGridColumnHeader Name="TopRightCornerHeader" Grid.Column="2" Template="{StaticResource TopRightHeaderTemplate}" /&gt; &lt;Rectangle Name="ColumnHeadersAndRowsSeparator" Grid.ColumnSpan="3" VerticalAlignment="Bottom" Width="Auto" StrokeThickness="1" Height="1" Fill="#FFC9CACA"/&gt; &lt;ScrollViewer Grid.ColumnSpan="2" Grid.Row="1"&gt; &lt;dataprimitives:DataGridRowsPresenter Name="RowsPresenter" /&gt; &lt;/ScrollViewer&gt; &lt;Rectangle Name="BottomRightCorner" Fill="#FFE9EEF4" Grid.Column="2" Grid.Row="2" /&gt; &lt;Rectangle Name="BottomLeftCorner" Fill="#FFE9EEF4" Grid.Row="2" Grid.ColumnSpan="2" /&gt; &lt;Grid Grid.Column="1" Grid.Row="2"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Rectangle Name="FrozenColumnScrollBarSpacer" /&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;Border x:Name="DisabledVisualElement" IsHitTestVisible="False" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" CornerRadius="2" Background="#8CFFFFFF" Opacity="0"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; </code></pre>
 

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