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:

  1. changing size of column 0 *
  2. changing size of column 1 auto
  3. changing size of row 1 *
  4. removing button.
  5. moving button [0, 1] or [1, 0]
  6. manually setting width of itemscontrol.
  7. setting verticalscrollbarvisibility of scrollviewer in itemscontrol 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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -