今天遇到这样一个问题,就是我做了一个自定义控件。然后加到StackPanel中,
<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);
如以上代码,无法得到垂直排列的效果。
解决方法就是要给控件设定高度和长度。
如下
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);