xml string 을 load 하여 화면에 보여주는 코드입니다.

(내용은 찰스패졸드 책 내용 인용)


using System.IO;

using System.Windows;

using System.Windows.Markup;

using System.Xml;


namespace WpfApp


    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window


        public MainWindow()




            string strXml = @"

<FlowDocument xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'



    <Paragraph TextAlignment='Center' FontSize='32' FontStyle='Italic'




    <Paragraph TextAlignment='Center'>

        &#x00A9; 2020 by kjun


    <Paragraph FontSize='16pt' FontWeight='Bold' LineHeight='16'>




        KJUN.KR is a sample program from kjun


            Applications = Code + Markup:

            A Guide to the Microsoft Windows Presentation Foundation


        published by Microsoft Press in 2020.

        XAML Cruncher provides a convenient way to learn about and experiment

        with XAML, the Extensible Application Markup Language.



        XAML Cruncher consists of an Edit section (in which you enter and edit

        a XAML document) and a Display section that shows the object created

        from the XAML. If the XAML document has errors, the text is displayed

        in red and the status bar indicates the problem.



        Most of the interface and functionality of the edit section of

        XAML Cruncher is based on Windows Notepad.


        <Bold>Xaml</Bold> menu provides additional features.


    <Paragraph FontSize='16pt' FontWeight='Bold' LineHeight='16'>

        Xaml Menu




        <Bold>Orientation</Bold> menu item lets you choose whether you

        want the Edit and Display sections of XAML Cruncher arranged

        horizontally or vertically.




        <Bold>Tab Spaces</Bold> menu item displays a dialog box that lets

        you choose the number of spaces you want inserted when you press the

        Tab key. Changing this item does not change any indentation

        already in the current document.



        There are times when your XAML document will be so complex that it

        takes a little while to convert it into an object. You may want to

        <Bold>Suspend Parsing</Bold> by checking this item on the

        <Bold>Xaml</Bold> menu.



        If you've suspended parsing, or if you want to reparse the XAML file,


        <Bold>Reparse</Bold> from the menu or press F6.



        If the root element of your XAML is

        <Italic>Window</Italic> ,

        XAML Cruncher will not be able to display the


        object in its own window.

        Select the

        <Bold>Show Window</Bold> menu item or press F7 to view

        the window.



        When you start up XAML Cruncher (and whenever you select

        <Bold>New</Bold> from the

        <Bold>File</Bold> menu), the Edit window

        displays a simple startup document.

        If you want to use the current document as the startup document,

        select the

        <Bold>Save as Startup Document</Bold> item.





            StringReader strreader = new StringReader(strXml);

            XmlTextReader xmlreader = new XmlTextReader(strreader);

            object obj = XamlReader.Load(xmlreader);


            Content = obj;










아래처럼 XML 에 frame 를 이용해 xml 파일을 지정할수도 있다.


<Window x:Class="WpfApp.MainWindow"







        Title="MainWindow" Height="400" Width="600">

    <Frame Source="kjunkr.xaml" />






'WPF' 카테고리의 다른 글

[WPF] static member 사용하기  (0) 2020.07.09
[WPF] ContextMenu  (0) 2020.07.08
[WPF] xml 로드하기  (0) 2020.07.08
[WPF] xml 16진수 값 0x0C은(는) 잘못된 문자입니다.  (0) 2020.07.08
[WPF] Hyperlink  (0) 2020.07.08
[WPF] Custom RoutedUICommand 만들기  (0) 2020.07.07

+ Recent posts