xaml - How can you make a WPF Expander stretch vertically within a vertical StackPanel -


given xaml below, possible make adjustment when either of expander items expanded, textblock content stretches vertically fill remaining space? (note xaml purposely simplified, solution must satisfy simple example , data bound itemssource scenario).

the stackpanel stretches fill space (since contained within grid), assume there conflict within stackpanel measuring code not allow infinitely large content elements. i'm not sure if possible resolve elegantly, may require manually overriding measuring code , determining optimal expanded height content container.

<grid>     <stackpanel>         <expander header="item 1">             <textblock background="lightcoral" text="content 1 should stretched vertically when expanded"/>         </expander>         <expander header="item 2">             <textblock background="lightblue" text="content 2 should stretched vertically when expanded"/>         </expander>     </stackpanel> </grid> 

note: read through how stackpanel's children fill maximum space downward? , not related question solution post use dockpanel not possible in data bound itemssource scenario.

stackpanel sets content height auto if placed inside grid control. 'grid' should used in place of stackpanel , set row height code behind. here example;

       <grid>              <grid.rowdefinitions>                 <rowdefinition x:name="row1" height="auto"/>                 <rowdefinition x:name="row2" height="auto"/>             </grid.rowdefinitions>             <expander header="item 1"  expanded="expander_expanded_1" verticalalignment="stretch" >                                    <textblock background="lightcoral" text="content 1 should stretched vertically when expanded" verticalalignment="stretch"/>                           </expander>             <expander header="item 2" grid.row="1" expanded="expander_expanded_2" verticalalignment="stretch" >                                    <textblock background="lightblue" text="content 2 should stretched vertically when expanded" verticalalignment="stretch"/>                          </expander>          </grid> 

and in code behind can set height of row on expanded event

private void expander_expanded_1(object sender, routedeventargs e)         {             ex2.height = new gridlength(1, gridunittype.auto);             ex1.height = new gridlength(1, gridunittype.star);         } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -