我正在尝试以 WPF 表单创建动态控件(标签和组合框),并相应地安排它们。这样做的最佳做法是什么,以及如何调整窗口大小以适应控件的增长?
public MainWindow()
{
MyEntities db = new MyEntities();
InitializeComponent();
var ID = db.Courses.Where(f => f.CourseId!=null).ToList();
foreach (var c in ID)
{
ComboBox c = new ComboBox();
this.stackpanel.Children.Add(c);
}
}
XAML
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel Name= "stackpanel"/>
</Window>