我有一個包含子StackPanels(在代碼後面添加)的StackPanel。StackPanel中的StackPanel對齊不正確
家長的StackPanel
<StackPanel Name="spDaysWeather" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Grid.Row="3" Orientation="Horizontal">
</StackPanel>
兒童StackPanels
for (int i=1;i<WeatherList.Count;i++)
{
StackPanel StackPanelDay = new StackPanel { Orientation =Orientation.Vertical, VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment= HorizontalAlignment.Stretch};
Label day = new Label { Content = WeatherList[i].weatherdate.DayOfWeek, FontSize = 10 };
System.Windows.Controls.Image imgweather = new System.Windows.Controls.Image { Source = ReturnCultureImage(String.Format("weather_{0}", WeatherList[i].condition.ToLower().Replace(" ", "_"))), Width = 75, Height = 75};
StackPanelDay.Children.Add(day);
StackPanelDay.Children.Add(imgweather);
spDaysWeather.Children.Add(StackPanelDay);
}
當我運行應用程序,我得到以下顯示
黑匣子是父的StackPanel。紅色正方形是我動態添加的子StackPanel。
我該如何讓孩子垂直居中,並調整應用窗口大小。
我應該使用StackPanel還是有另一個面板更適合?
非常感謝
你在第一次嘗試的HorizontalAlignment = 「中心」? – Paparazzi 2012-03-21 11:38:31