Loading a WPF Silverlight Stackpanel dynamically

I'm using Silverlight 5 and C# and have a need to load a specific StackPanel dynamically at runtime depending upon a certain user input selection.

Is there a way to replace a named StackPanel with XAML stored in a database?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Maybe this will help.

You can use any type as a data source as long as it has a public parameterless constructor and at least one public property. Here's a sample of binding to System.String. In the example below, both TextBlock elements have a name, which makes them accessible in the *.cs/vb file. You set the textBox2 binding in the XAML file and the data context in the code behind:

 <StackPanel Margin='20'>
    <Label>Via Code:</Label>
    <TextBlock x:Name='tb1'
               Text="" />
<Label>Via Binding:</Label>
    <TextBlock x:Name='tb2'
               Text="{Binding}" />

Open in new window

string sample;
public BindingToString()
  sample = "ABC DEF GHI JKL MNO PQR";
  // assign directly to the Text property
  tb1.Text = sample;
  // register with the binding system
  tb2.DataContext = sample;
  // there must also be a binding in the XAML
  // or here in code

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aaron JabamaniTechnical ArchitectCommented:
Looks like it is possible. But you also have to manage events for them. Hope this link helps you, http://www.kastory.net/index.php?option=com_content&view=article&id=29:xaml-remote-loading-with-event-hooking&catid=9&Itemid=131
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.