Reputation: 952
I have a DataGrid which is -90 degree rotated and rows of each columns will be added horizontally. I think this is not difficult to understand.
However, if I scroll down the DataGrid, the content of highest position(Top) starts to disappear one by one as scrolling down but re-appears if I scroll up back to there again.
It seems DataGrid throws the passed-column away and tries to focus on current and next column efficiently for good performance.
I don't want content of columns disappears but all the contents show always as usual.
As a reference, My DataGrid only has 6 columns vertically located on left and each column will only have 1 row horizontally. And the content of some rows are long text with 20~ 30 lines.
Here is my simple code and screenshot.
Please help me with excellent advice. Thank you so much ! (Now, here in Far-East Asia is Mid-Night, so, my comment will be available on tomorrow morning)
<DataGrid x:Name="dataGrid_Medicineinformation" HorizontalAlignment="Left" VerticalAlignment="Top" Height="Auto" BorderThickness="0" AutoGenerateColumns="False" UseLayoutRounding="True" RenderTransformOrigin="0.5,0.5" IsReadOnly="True" RowHeight="NaN" RowDetailsVisibilityMode="Collapsed" ColumnWidth="Auto" VerticalScrollBarVisibility="Disabled" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" EnableColumnVirtualization="True">
<DataGrid.Resources>
<Style x:Key="DataGridBase" TargetType="Control">
<Setter Property="LayoutTransform">
<Setter.Value>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Setter.Value>
</Setter>
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
</Style >
<Style TargetType="DataGridCell" BasedOn="{StaticResource DataGridBase}"/>
<Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource DataGridBase}"/>
<Style TargetType="DataGridRowHeader" BasedOn="{StaticResource DataGridBase}"/>
</DataGrid.Resources>
<DataGrid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90" />
<MatrixTransform Matrix="-1, 0, 0, 1, 0, 0" />
</TransformGroup>
</DataGrid.LayoutTransform>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel>
<StackPanel.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90" />
<MatrixTransform Matrix="-1, 0, 0, 1, 0, 0" />
</TransformGroup>
</StackPanel.LayoutTransform>
<TextBlock Height="100" Text="Binding Image" />
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Effect>
<DropShadowEffect/>
</DataGrid.Effect>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding productname}" Header="제품명" Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Left"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding substancename_korean}" Header="성분명(한글)" Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Left"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding substancename}" Header="성분명(영문)" Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Left"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding dosage}" Header="용법 · 용량" Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="TextAlignment" Value="Left"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding efficacy}" Header="효능 · 효과" Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="TextAlignment" Value="Left"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding precautions}" Header="사용상의 주의사항" Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="TextAlignment" Value="Left"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Upvotes: 0
Views: 2095
Reputation: 952
My situation consists of 2 matters as horizontal DataGrid and Virtualization. Somebody provided a solution linked on https://social.msdn.microsoft.com/Forums/vstudio/en-US/4b95587d-df29-45db-b265-8c3bab77f2a4/c-wpf-virtualization-datagrid-content-of-column-disappears-when-scrolling-but-reappears-when?forum=wpf
I hope this helps someone else.
Upvotes: 0
Reputation: 18578
Seems like problem with the virtualization. Can you try switching virtualization off by setting
VirtualizingStackPanel.IsVirtualizing = "false", VirtualizingStackPanel.VirtualizationMode="Standard" and EnableColumnVirtualization="false"
on your datagrid and check if this behaviour stays.
Upvotes: 3