应该是DataGrid中的水平滚动条不会消失 [英] Horizontal scrollbar in DataGrid does not disappear when it should
问题描述
你好,
我有一个DataGrid,它根据附近下拉列表中的类别选择显示数据。在这个DataGrid中,我只有1列。
绑定:ItemsSource =" {Binding SearchResults}"其中SearchResults是ObservableCollection。
Scrollbar:Visibility =" {TemplateBinding ComputedHorizontalScrollBarVisibility}"来自ScrollViewer
对于第一类水平滚动条,当文本行太长(红色)且水平滚动条显示正确时,工作正常。
Hello,
I have a DataGrid that displays data based on selection of categories from nearby drop-down. In this DataGrid I have only 1 column.
Binding: ItemsSource="{Binding SearchResults}" where SearchResults is ObservableCollection.
Scrollbar: Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" from ScrollViewer
For 1st category horizontal scrollbar works fine when there is a row with text too long (red colour) and horizontal scrollbar appears correctly.
当我用drop更改为第2类时-down没有结果(所以SearchResults为空),滚动条消失。
Also when I change to 2nd category with drop-down with no results (so SearchResults are empty), scrollbar disappears.
但是当我更改为第3个类别且结果超过0时,滚动条会重新出现,其长度与第一个类别相同,长文本,即使没有长文本行!
But when I change to 3rd category with more than 0 results, scrollbar reappears with the same size as was in the 1st category with long text, even though there is no row with long text!
如果我永远不会去第一类(这么长的文字从未显示过)然后它也适用于第三类,滚动条不会出现...
$
我不喜欢垂直滚动条有问题all(两者的设置相同)。
$
这是某种默认行为吗?我在网上找不到任何东西,我试过没有帮助。
感谢您的帮助!
$
$ b $bMiloš ,斯洛伐克
If I never go to 1st category (so long text has never been displayed) then it works fine also for 3rd category and scrollbar doesn't appear...
I don't have a problem with vertical scrollbar at all (settings for both of them are the same).
Is this some kind of default behaviour? I couldn't find anything online and nothing I tried helped.
Thanks for help!
Miloš, Slovakia
推荐答案
嗨Miloš,
Hi Miloš,
请看下面的d uplicate
主题,此处有详细信息e < span class ="x_x_short_text"id ="x_x_result_box"lang ="en"tabindex =" - 1"> xplanation。
Look at following duplicate thread, here have a detail explanation.
所以
So.
当ObservableCollection发生变化时添加以下代码。
Add following code when the ObservableCollection changed.
public ObservableCollection<category> SearchResults
{
get { return _searchResults; }
set {
_searchResults = value;
RaisePropertyChanged("SearchResults");
foreach (DataGridColumn c in dg.Columns)
c.Width = 0;
// Update your DG's source here
foreach (DataGridColumn c in dg.Columns)
c.Width = DataGridLength.Auto;
}
}
或者在ComboBox_SelectionChanged事件中。
Or in ComboBox_SelectionChanged event.
Best问候,
Bob
这篇关于应该是DataGrid中的水平滚动条不会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!