views:

1887

answers:

4

So I'm new to SL coming from a WinForms background where I could instantiate a UserControl or Form like this:

MyForm frm = new MyForm();
frm.ShowDialog();

So in SL, I created a simple Page.xaml and a second xaml file called Page2.xaml - I dropped a button in the Page.xaml file and within that button's click event, I tried adding the following to call the 2nd xaml file:

private void btnLoad_Click(object sender, RoutedEventArgs e)
{
    Page2 frm2 = new Page2();
    frm2.  // ?? don't know what write here ??
}

How can I call XAML UserControls?

A: 

I believe in silverlight what you actually need to do is Navigate to a separate page.

It is a web platform so Navigate is the web form of winforms. show() method.

Peter
+1  A: 

In order to nagivate to a completely different silverlight page you will need a "container" usercontrol with your main page inside of it. From there you can set your internal UserControl like so:

insideControl = new Page2();

For more information: http://silverlight.net/learn/learnvideo.aspx?video=56933

Corey Sunwold
Great, I did the following and was able to load my form: this.Content = new Page2();But not exactly what I'm looking for. I would like for Page2() to come up as a "subform", i.e. sort of as a modal form. How can I do this?
You could use the popup control.
Corey Sunwold
A: 

The XamlReader class has been developped exactly for that purpose. Using its Load or Parse methods will return you the objects that would have been generated by your Xaml.

A: 

You have to create a UserControl.xaml that is tehe container from page.xaml and page2.xaml

this container have a grid with x:Name="miGrid" :

< Grid x:Name="miGrid" />

after you load in childrens of this control the instance of user control in this case frm2..

miGrid.Childrens.Clear(); miGrid.Childrens.Add(frm2);

Pablo