c# - ScrollViewer in ItemsControl - ScrollBar not shown but working -
this not average "my scrollviewer isn't working" question...
assume window grid. sizes of column 0 , row 1 set auto
, column 1 , row 0 set *
. (important)
in cell [0, 0] there itemscontrol
template stackpanel
inside scrollviewer
inside grid
. reason simple: show scroll bar if not items in itemscontrol
can displayed. visibility of vertical scrollbar set auto
(important).
in cell [1, 1] there button
displays width.
if window small display items in itemscontrol
lead following: scroll bar there not visible. working, because can scroll using mouse wheel. reason seems grid column in itemscontrol
contained not automatically extended make space scrollbar.
if change (nearly) any of parameters, scroll bar displayed expected , second column reduced in size. can explain odd behavior?
additional info:
the following parameter changes lead scrollbar becoming visible:
- changing size of column 0
*
- changing size of column 1
auto
- changing size of row 1
*
- removing
button
. - moving
button
[0, 1] or [1, 0] - manually setting width of
itemscontrol
. - setting
verticalscrollbarvisibility
ofscrollviewer
initemscontrol
visible
.
however, changing button in [1, 1] else, e.g. itemscontrol
doesn't change strange behavior, has nothing button. furthermore, changing width of button
smaller second column, doesn't remove behavior.
complete sample code reproduction:
<window x:class="wpfapplication4.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="343" width="253"> <grid> <grid.columndefinitions> <columndefinition width="auto" /> <columndefinition width="*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="*" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <itemscontrol> <itemscontrol.template> <controltemplate> <grid> <grid.rowdefinitions> <rowdefinition height="*" /> </grid.rowdefinitions> <scrollviewer verticalscrollbarvisibility="auto"> <stackpanel isitemshost="true" /> </scrollviewer> </grid> </controltemplate> </itemscontrol.template> <itemscontrol.items> <button content="column1" height="500" /> </itemscontrol.items> </itemscontrol> <button content="{binding actualwidth, relativesource={relativesource self}}" grid.column="1" grid.row="1" /> </grid> </window>
looks might known bug in wpf. this question deals listbox's scrollviewer, think principal same.
as alternative, add behind scrollviewer has it's width bound scrollviewer's actualwidth, force column draw correct size
<grid> <grid.columndefinitions> <columndefinition width="auto" /> <columndefinition width="*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="*" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <scrollviewer x:name="test" grid.row="0" grid.column="0" verticalscrollbarvisibility="auto"> <button content="column1" height="500" /> </scrollviewer> <grid grid.column="0" grid.row="0" width="{binding elementname=test, path=actualwidth}" /> <button content="{binding actualwidth, relativesource={relativesource self}}" grid.column="1" grid.row="1" /> </grid>
Comments
Post a Comment