Silverlight 4: Dynamically add a HyperlinkButton to a stackpanel

落花浮王杯 提交于 2019-12-24 08:41:04

问题


I would like to retrieve a list of links from SQLServer, and programmatically create some HyperlinkButtons from that list. These buttons should be added to a StackPnael. What is the best way to do this?

Something along the lines of:

    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>

回答1:


LinksStackPanel.Children.Add(btn);


来源:https://stackoverflow.com/questions/3893928/silverlight-4-dynamically-add-a-hyperlinkbutton-to-a-stackpanel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!