Problem: WPF listbox horizontal scrollbar last screen display incomplete last line of
code is as follows:
-
<ListBox
-
Width=
"200"
-
Height=
"200"
-
FontSize=
"18"
-
>
-
<ListBoxItem>item1
</ListBoxItem>
-
<ListBoxItem>item2
</ListBoxItem>
-
<!-----item3,4...13------->
-
<ListBoxItem>item14
</ListBoxItem>
-
<ListBoxItem>item15=================
</ListBoxItem>
-
<ListBoxItem>item16
</ListBoxItem>
-
<!-----item17,18...21------->
-
<ListBoxItem>item22
</ListBoxItem>
-
</ListBox>
Phenomenon: listbox items in an amount sufficient to display the vertical scroll bar,
the first item the last screen (upper item15 ===) is too long that the horizontal scroll bar display listbox.
Solution:
In the listbox by adding the following:
ScrollViewer.CanContentScroll = "False"
or another horizontal scroll bar is always displayed
ScrollViewer.HorizontalScrollBarVisibility = "Visible"
Analysis:
Default ScrollViewer.CanContentScroll = "True", click on the listbox vertical scroll bar to scroll down when a height of each item of rolling,
at this time, when the last screen, since the horizontal scroll bar appears, blocking the last row.
ScrollViewer.CanContentScroll = "False" when a continuous scroll down, ListBox can scroll to the bottom. The above problem does not exist.
The
ScrollViewer.HorizontalScrollBarVisibility = "Visible", because it has been shown that there is no problem to occupy listbox height.
Reproduced in: https: //my.oschina.net/xhan/blog/24443