첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ ResourcePage.xaml

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    Title="리소스 페이지">
    <Grid>
        <Ellipse
            Margin="50"
            Fill="RoyalBlue" />
    </Grid>
</Page>

 

728x90

 

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="Application 클래스 : GetResourceStream 정적 메소드를 사용해 리소스 XAML 페이지 로드하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Frame Name="frame"
        Margin="10"
        BorderThickness="1"
        BorderBrush="Black" />
</Window>

 

반응형

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Resources;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            Uri uri = new Uri("/RESOURCE/ResourcePage.xaml", UriKind.Relative);
          //Uri uri = new Uri("pack://application:,,,/TestProject;component/RESOURCE/ResourcePage.xaml", UriKind.Absolute);

            StreamResourceInfo info = Application.GetResourceStream(uri);

            XamlReader reader = new XamlReader();

            Page page = (Page)reader.LoadAsync(info.Stream);

            this.frame.Content = page;
        }

        #endregion
    }
}

※ ResourcePage.xaml 파일은 [빌드 작업] 항목을 [Resource]로 설정한다.

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요