Silverlight 2.0小技巧(4) ReDirectXmalPage

摘要:Silverlight 2.0小技巧(4) DirectXmalPage

若要從page.xaml 轉到 page1.xaml (或 page1.xmal 轉回 page.xmal)


page.xmal  and page1.xmal


<Grid x:Name="LayoutRoot" Background="White">
        <Button Margin="160,128,160,140" Content="Page" Click="Button_Click"/>
 </Grid>


page.xmal.cs


     private void Button_Click(object sender, RoutedEventArgs e)
        {
            Type type = typeof(Page).Assembly.GetType("ReDirectPage.Page1", false);
            //namespace ReDirectPage
            UIElement element = Activator.CreateInstance(type) as UIElement;
            LayoutRoot.Children.Add(element);
        }


page1.xmal.cs


    private void Button_Click(object sender, RoutedEventArgs e)
        {
            Type type = typeof(Page).Assembly.GetType("ReDirectPage.Page", false);
            //namespace ReDirectPage
            UIElement element = Activator.CreateInstance(type) as UIElement;
            LayoutRoot.Children.Add(element);
        }


註:並不用刻意去移除LayoutRoot.Children 的element