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?
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

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.