我想从SQLServer检索链接列表,并以编程方式从该列表中创建一些HyperlinkButtons。这些按钮应添加到StackPnael。这样做的最佳方式是什么?
有些事情:
private void RefreshMenu()
{
var dc = new FrameworkCMSDomainContext();
var query = dc.GetCMSPagesForSectionQuery(Section);
dc.Load(query, (s) =>
{
foreach(var page in dc.CMSPages)
{
HyperlinkButton btn = new HyperlinkButton();
btn.NavigateUri = new Uri("/" + Section + "/" + page.Name, UriKind.Relative);
btn.Content = page.Name;
btn.TargetName = "ContentFrame";
//Add to stackpanel here
}
}, null);
}
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel x:Name="LinksStackPanel" Orientation="Vertical">
</StackPanel>
<Button x:Name="AddPage" Click="AddPage_Click">Add</Button>
</Grid>
答案 0 :(得分:3)
LinksStackPanel.Children.Add(btn);