wpf - Prevent controls from forcing parents to resize -


i'm going nuts trying figure out. i've got dockpanel stuff docked top, , itemscontrol center content (which presents wrappanel containing more dockpanels).

i want center itemscontrol expand width of parent dockpanel necessary. don't want stuff docked top of dockpanel cause dockpanel expand, would use whatever space has been requested width of itemscontrol.

here's simplified xaml still captures behavior:

<window x:class="sizingtest.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="mainwindow" sizetocontent="width" height="150">     <grid>         <dockpanel>             <textblock dockpanel.dock="top">here's long text should not force window expand. clip if it's wider buttons.</textblock>             <wrappanel orientation="vertical">                 <button>button 1</button>                 <button>button 2</button>                 <button>button 3</button>                 <button>button 4</button>                 <button>button 5</button>                 <button>button 6</button>                 <button>button 7</button>                 <button>button 8</button>                 <button>button 9</button>                 <button>button 10</button>             </wrappanel>         </dockpanel>     </grid> </window> 

in other words, wrappanel/dockpanel/grid/window should adjust width accommodate wrappanel's columns of buttons, want textblock clipped after exhausting available space wrappanel requested. resizing window height (which causes wrappanel adjust , add/remove columns) should cause textblock change width - , clip - match wrappanel. how make work?

you need make couple of changes. first, need wrappanel not stretch across full width. can data bind textblock.width property wrappanel.actualwidth property. finally, you'll need set horizontalalignment property left on textblock well. should trick:

<grid>     <dockpanel>         <textblock dockpanel.dock="top" horizontalalignment="left"              width="{binding actualwidth, elementname=panel}" text="here's              long text should not force window expand..." />         <wrappanel name="panel" orientation="vertical" horizontalalignment="left">             <button>button 1</button>             <button>button 2</button>             <button>button 3</button>             <button>button 4</button>             <button>button 5</button>             <button>button 6</button>             <button>button 7</button>             <button>button 8</button>             <button>button 9</button>             <button>button 10</button>         </wrappanel>     </dockpanel> </grid> 

a final note better if used texttrimming property add ellipsis (...) @ end of text before cut off. this:

<textblock dockpanel.dock="top" horizontalalignment="left" width="{binding actualwidth,     elementname=panel}" text="here's long text should not force      window expand..." texttrimming="characterellipsis" /> 

enter image description here


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -