cmaduro
cmaduro

Reputation: 1722

Silverlight 4: Dynamically add a HyperlinkButton to a stackpanel

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>

Upvotes: 1

Views: 2729

Answers (1)

Stephan
Stephan

Reputation: 5488

LinksStackPanel.Children.Add(btn);

Upvotes: 3

Related Questions