c# - How to set height to the dynamically added user control in stackpanel? -


we having wpf user control (usercontrol.xaml) in 1 dll (child.dll).

we added reference of "child.dll" in application (parentapplication)

in parent application have 1 stackpanel in have add user control dynamically using user control constructor.

parentapplication contains :

mainwindow.xaml

<window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:fa="http://schemas.fontawesome.io/icons/" x:class="parentapplication.mainwindow"         xmlns:mvis="clr-namespace:mvis;assembly=mvis"         title="mainwindow" height="1000" width="1000" windowstartuplocation="centerscreen" windowstate="maximized"> <grid>         <tabcontrol> <tabitem cursor="hand">                 <tabitem.header>                     <stackpanel orientation="horizontal">                         <textblock text="childapplication"/>                     </stackpanel>                 </tabitem.header>                 <grid>                     <grid.rowdefinitions>                         <rowdefinition height="*"></rowdefinition>                     </grid.rowdefinitions>                     <scrollviewer horizontalscrollbarvisibility="auto" verticalscrollbarvisibility="auto" cancontentscroll="true" grid.row="0" >                         <stackpanel x:name="usercontrolplaceholder" background="blue"/>                     </scrollviewer>                 </grid>             </tabitem>         </tabcontrol> </grid> </window> 

so doing on mainwindow.xaml.cs :

public partial class mainwindow : window {         public mainwindow()         {             initializecomponent();             usercontrol usercontrol = new usercontrol();             this.usercontrolplaceholder.children.add(usercontrol);                    } } 

issue 1: user control displayed in half height of screen.

**note: did not set height usercontrol.xaml , can not set height control height usercontrol.height=200; **

issue 2: have used scroll viewer in mainwindow.xaml, when resize application window, vertical scroll bar not displayed.

remove stackpanel , add usercontrol directly scrollviewer:

<tabitem cursor="hand">     <tabitem.header>         <stackpanel orientation="horizontal">             <textblock text="childapplication"/>         </stackpanel>     </tabitem.header>     <grid>         <grid.rowdefinitions>             <rowdefinition height="*"></rowdefinition>         </grid.rowdefinitions>         <scrollviewer x:name="sv" horizontalscrollbarvisibility="auto" verticalscrollbarvisibility="auto" cancontentscroll="true" grid.row="0" >          </scrollviewer>     </grid> </tabitem> 

this.sv.content = usercontrol;         

scrollviewers , stackpanels don't work together:

horizontal scroll stackpanel doesn't work


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -