StackPanel在增長控件的問題

今天遇到這樣一個問題,就是我作了一個自定義控件。而後加到StackPanel中, io

<StackPanel Height="676" HorizontalAlignment="Left"       Name="stackPanel1"  Width="180"  Orientation="Vertical" >
</StackPanel>方法

    WinUserInfo winUserInfo = new WinUserInfo();
           stackPanel1.Children.Add(winUserInfo);
            WinUserInfo winUserInfo1 = new WinUserInfo();
              stackPanel1.Children.Add(winUserInfo1);
              WinUserInfo winUserInfo2 = new WinUserInfo();
           stackPanel1.Children.Add(winUserInfo2);new

如以上代碼,沒法獲得垂直排列的效果。控件

解決方法就是要給控件設定高度和長度。

以下 

  WinUserInfo winUserInfo = new WinUserInfo();
            winUserInfo.Height = 220;
            winUserInfo.Width = 201;

            stackPanel1.Children.Add(winUserInfo);            WinUserInfo winUserInfo1 = new WinUserInfo();            winUserInfo1.Height = 220;            winUserInfo1.Width = 201;            stackPanel1.Children.Add(winUserInfo1);             WinUserInfo winUserInfo2 = new WinUserInfo();            winUserInfo2.Height = 220;            winUserInfo2.Width = 201;            stackPanel1.Children.Add(winUserInfo2);

相關文章
相關標籤/搜索