layout - WPF keep control from affecting scrollviewer width? -
is there way prevent wrap panel (or other control) participating in scrollviewers width calculation? example below, i'd wrap panel stay within width created other controls not directly affect width calculation. (i.e.) i'd behavior similar if auto off, still allow horizontal scrolling of other content gets wider.
<window x:class="mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <scrollviewer horizontalscrollbarvisibility="auto"> <grid> <grid.columndefinitions> <columndefinition width="100" /> <columndefinition width="1*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <wrappanel grid.column="1" name="ctlwrap" /> <textbox grid.row="1" grid.column="1" width="100" horizontalalignment="left" name="ctltext" /> <stackpanel grid.row="2" grid.column="1" orientation="horizontal"> <button click="button_click">add wrap</button> <button click="button_click_1">remove wrap</button> <button click="button_click_2">add text</button> <button click="button_click_3">remove text</button> </stackpanel> </grid> </scrollviewer> </grid> </window>
here's code used buttons:
class mainwindow private sub button_click(sender object, e routedeventargs) ctlwrap.children.add(new button {.content = "button " & ctlwrap.children.count + 1}) end sub private sub button_click_1(sender object, e routedeventargs) if ctlwrap.children.count ctlwrap.children.removeat(ctlwrap.children.count - 1) end if end sub private sub button_click_2(sender object, e routedeventargs) ctltext.width += 30 end sub private sub button_click_3(sender object, e routedeventargs) if ctltext.width > 60 ctltext.width -= 30 end sub end class
i capitulated slightly. put buttons in left column of grid , bound width , maxwidth viewportwidth of scroller , left margin horizatonal offset.
<window x:class="mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:wpfapplication14" title="mainwindow" height="350" width="525"> <window.resources> <app:marginconverter x:key="mc" /> </window.resources> <grid> <scrollviewer horizontalscrollbarvisibility="auto" name="ctlscroll"> <grid> <grid.columndefinitions> <columndefinition width="100" /> <columndefinition width="1*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <wrappanel grid.columnspan="2" grid.column="0" name="ctlwrap" width="{binding viewportwidth, elementname=ctlscroll}" maxwidth="{binding viewportwidth, elementname=ctlscroll}" margin="{binding horizontaloffset, elementname=ctlscroll, converter={staticresource mc}}" horizontalalignment="left" /> <textbox grid.row="1" grid.column="1" width="100" horizontalalignment="left" name="ctltext" /> <stackpanel grid.row="2" grid.column="1" orientation="horizontal"> <button click="button_click">add wrap</button> <button click="button_click_1">remove wrap</button> <button click="button_click_2">add text</button> <button click="button_click_3">remove text</button> </stackpanel> </grid> </scrollviewer> </grid> </window>
the margin converter came here.
Comments
Post a Comment