실버라이트 관련 팁 모음

시삽: 레드플러스 님 
게시판 이동:
 제목 : Page.xaml에서 Page2.xaml로 이동하는 예제
글번호: 2
작성자: 레드플러스
작성일: 2008/06/22 오후 4:01:18
조회수: 4102
1. 3개의 XAML을 작성한다.

Page.xaml
Page2.xaml
PageSwitcher.xaml

2. App.xaml.cs의 시작개체를 PageSwitcher로 잡는다.

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new PageSwitcher();
        }

3. 내용이 없는 PageSwitcher.xaml을 아래와 같이 만든다.

PageSwitcher.xaml

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="SilverlightApplication1.PageSwitcher"
    d:DesignWidth="640" d:DesignHeight="480">
</UserControl>

PageSwitcher.xaml.cs

using System.Windows.Controls;

namespace SilverlightApplication1
{
    public partial class PageSwitcher : UserControl
    {
        public PageSwitcher()
        {
            // Required to initialize variables
            InitializeComponent();

            if (this.Content == null)
            {
                this.Content = new Page();    
            }
        }

        public void Navigate(UserControl nextPage)
        {
            this.Content = nextPage;
        }
    }
}

4. Page.xaml에서 Page2.xaml로 이동하는 코드 예제

        private void btnSwitch_Click(object sender, RoutedEventArgs e)
        {
            PageSwitcher ps = this.Parent as PageSwitcher;
            ps.Navigate(new Page2());
        }

/// 언젠간 쓸일을 대비하여...
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트

(댓글을 남기려면 로그인이 필요합니다.)

관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 3 - 레드플러스 2008-06-22 2616
현재글 Page.xaml에서 Page2.xaml로 이동하는 예제 - 레드플러스 2008-06-22 4102
다음글 Silverlight only supports http as the streaming... - 레드플러스 2008-05-14 2668
 
손님 사용자 Anonymous (손님)
로그인 Home