我正面临一个问题。 在我看来,我有一个DataGrid,其水平滚动条的可见性设置为自动。 我面临的问题是,即使有足够的空间让DataGrid扩展并完全显示自己,滚动条也会一直出现。 我已经尝试了几乎所有的东西,但无法弄清楚什么是错的。
我上传了一个示例应用程序来证明这里的问题。 希望有人能指出我正在制造的错误。
I am facing an issue. In my view I have a DataGrid whose Horizontal Scroll Bar's Visibility is set to Auto. Problem I am facing is that the scroll bar is appearing all the time even if there is enough space for DataGrid to expand and completely display itself. I have tried almost everything but couldn't figure out whats is wrong.
I have uploaded a sample application to demonstrate the problem here. Hoping anyone will point out mistake I am making.
最满意答案
我做了以下更改/解决方法来解决问题。 它可能不是完美的解决方案,但对我有用。
我在Grid添加了两个列,一个在开头,另一个在结尾。
<Grid.ColumnDefinitions> <ColumnDefinition Width="{Binding ElementName=m_DataGrid, Path=RowHeaderWidth}" /> <ColumnDefinition Width="{Binding ElementName=col1, Path=ActualWidth}" /> <ColumnDefinition Width="{Binding ElementName=col2, Path=ActualWidth}" /> <ColumnDefinition Width="{Binding ElementName=col3, Path=ActualWidth}" /> <ColumnDefinition Width="{Binding ElementName=col4, Path=ActualWidth}" /> <ColumnDefinition x:Name="specialCol" /> </Grid.ColumnDefinitions>然后我增加了DataGrid的ColumnSpan
...Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="6" ....
然后我在Constrcutor of Window添加了这一行
specialCol.Width = new GridLength (2);
并将UpdateGrid方法更改为此
void UpdateGrid() { ScrollViewer scrollview = FindVisualChild<ScrollViewer>(m_DataGrid); Visibility verticalVisibility = scrollview.ComputedVerticalScrollBarVisibility; if (verticalVisibility == System.Windows.Visibility.Visible) { specialCol.Width = new GridLength(20); m_Border.Width = m_DataGrid.ActualWidth - m_DataGrid.RowHeaderWidth - 17; } else { specialCol.Width = new GridLength(2); m_Border.Width = m_DataGrid.ActualWidth - m_DataGrid.RowHeaderWidth; } }在需要之前,我现在看不到任何HorizontalScrollBar
I did following changes/workarounds to solve the issue. It might not be the perfect solution but works for me.
I added two more columns in the Grid, one in the start and one at the end.
<Grid.ColumnDefinitions> <ColumnDefinition Width="{Binding ElementName=m_DataGrid, Path=RowHeaderWidth}" /> <ColumnDefinition Width="{Binding ElementName=col1, Path=ActualWidth}" /> <ColumnDefinition Width="{Binding ElementName=col2, Path=ActualWidth}" /> <ColumnDefinition Width="{Binding ElementName=col3, Path=ActualWidth}" /> <ColumnDefinition Width="{Binding ElementName=col4, Path=ActualWidth}" /> <ColumnDefinition x:Name="specialCol" /> </Grid.ColumnDefinitions>Then I increased the ColumnSpan of DataGrid
...Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="6" ....
Then I added this line in Constrcutor of Window
specialCol.Width = new GridLength (2);
and changed UpdateGrid method to this
void UpdateGrid() { ScrollViewer scrollview = FindVisualChild<ScrollViewer>(m_DataGrid); Visibility verticalVisibility = scrollview.ComputedVerticalScrollBarVisibility; if (verticalVisibility == System.Windows.Visibility.Visible) { specialCol.Width = new GridLength(20); m_Border.Width = m_DataGrid.ActualWidth - m_DataGrid.RowHeaderWidth - 17; } else { specialCol.Width = new GridLength(2); m_Border.Width = m_DataGrid.ActualWidth - m_DataGrid.RowHeaderWidth; } }I don't see any HorizontalScrollBar now until it is required
更多推荐
DataGrid,问题,滚动,电脑培训,计算机培训,IT培训"/> <meta name="description&qu
发布评论