我有一个旋转-90度的DataGrid,每列的行将水平添加。我认为这并不难理解。
但是,如果我向下滚动DataGrid,最高位置(Top)的内容会随着向下滚动逐渐消失,但如果我再次向上滚动到那里则会重新出现。
似乎DataGrid抛弃了传递列,并试图有效地关注当前和下一列以获得良好的性能。
我不希望列的内容消失,但所有内容都像往常一样显示。
作为参考,My DataGrid只有6列垂直位于左侧,每列只有1行水平。并且一些行的内容是长文本,有20~30行。
这是我的简单代码和截图。
请帮助我提出好的建议。非常感谢 ! (现在,在远东亚洲是午夜,所以,我的评论将在明天早上发布)
<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>
答案 0 :(得分:3)
似乎与虚拟化有关。您可以尝试通过设置
来关闭虚拟化VirtualizingStackPanel.IsVirtualizing = "false", VirtualizingStackPanel.VirtualizationMode="Standard" and EnableColumnVirtualization="false"
在您的数据网格上并检查此行为是否仍然存在。
答案 1 :(得分:0)
我的情况包括两个问题,如水平DataGrid和虚拟化。 有人在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
上提供了一个解决方案我希望这有助于其他人。