■ 도움말 윈도우 사용하기

----------------------------------------------------------------------------------------------------


TestProject.zip


HelpWindow.xaml

 

 

<Window x:Class="TestProject.HelpWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    WindowStartupLocation="CenterScreen"

    Width="800"

    Height="600"

    Title="도움말"

    FontFamily="나눔고딕코딩"

    FontSize="16"

    ShowInTaskbar="False">

    <Window.Resources>

        <XmlDataProvider x:Key="XMLDataProviderKey"

            Source="Help/HelpContents.xml"

            XPath="HelpContents" />

        <HierarchicalDataTemplate DataType="Topic" ItemsSource="{Binding XPath=Topic}">

            <StackPanel Orientation="Horizontal">

                <Image Name="image"

                    Margin="2"

                    Stretch="None"

                    Source="Help/HelpImageQuestionMark.png" />

                <TextBlock

                    VerticalAlignment="Center"

                    FontSize="12pt"

                    Text="{Binding XPath=@Header}" />

            </StackPanel>

            <HierarchicalDataTemplate.Triggers>

                <DataTrigger

                    Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=HasItems}"

                    Value="True">

                    <Setter TargetName="image" Property="Image.Source" Value="Help/HelpImageClosedBook.png" />

                </DataTrigger>

                <DataTrigger

                    Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsExpanded}"

                    Value="True">

                    <Setter

                        TargetName="image"

                        Property="Image.Source"

                        Value="Help/HelpImageOpenBook.png" />

                </DataTrigger>

            </HierarchicalDataTemplate.Triggers>

        </HierarchicalDataTemplate>

    </Window.Resources>

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="33*" />

            <ColumnDefinition Width="Auto" />

            <ColumnDefinition Width="67*" />

        </Grid.ColumnDefinitions>

        <TreeView Name="treeView" Grid.Column="0"

            ItemsSource="{Binding Source={StaticResource XMLDataProviderKey}, XPath=Topic}"

            SelectedValuePath="@Source"

            SelectedItemChanged="treeView_SelectedItemChanged" />

        <GridSplitter Grid.Column="1"

            HorizontalAlignment="Center"

            VerticalAlignment="Stretch"

            Width="6" />

        <Frame Name="frame" Grid.Column="2"

            Navigated="frame_Navigated" />

    </Grid>

</Window>

 

 

HelpWindow.cs

 

 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Navigation;

using System.Xml;

 

namespace TestProject

{

    /// <summary>

    /// 도움말 윈도우

    /// </summary>

    public partial class HelpWindow

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - HelpWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public HelpWindow()

        {

            InitializeComponent();

 

            this.treeView.Focus();

        }

 

        #endregion

        #region 생성자 - HelpWindow(topicURI)

 

        /// <summary>

        /// 생성자

        /// </summary>

        /// <param name="topicURI">항목 URI</param>

        public HelpWindow(string topicURI) : this()

        {

            if(topicURI != null)

            {

                this.frame.Source = new Uri(topicURI, UriKind.Relative);

            }

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 트리 뷰 선택 항목 변경시 처리하기 - treeView_SelectedItemChanged(sender, e)

 

        /// <summary>

        /// 트리 뷰 선택 항목 변경시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)

        {

            if(this.treeView.SelectedValue != null)

            {

                this.frame.Source = new Uri(this.treeView.SelectedValue as string, UriKind.Relative);

            }

        }

 

        #endregion

        #region 프레임 탐색시 처리하기 - frame_Navigated(sender, e)

 

        /// <summary>

        /// 프레임 탐색시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void frame_Navigated(object sender, NavigationEventArgs e)

        {

            if(e.Uri != null && e.Uri.OriginalString != null && e.Uri.OriginalString.Length > 0)

            {

                FindItemToSelect(this.treeView, e.Uri.OriginalString);

            }

        }

 

        #endregion

        #region 선택하기 위한 항목 찾기 - FindItemToSelect(itemsControl, source)

 

        /// <summary>

        /// 선택하기 위한 항목 찾기

        /// </summary>

        /// <param name="itemsControl">ItemsControl 객체</param>

        /// <param name="source">소스 문자열</param>

        /// <returns>처리 결과</returns>

        private bool FindItemToSelect(ItemsControl itemsControl, string source)

        {

            foreach(object item in itemsControl.Items)

            {

                XmlElement xmlElement = item as XmlElement;

 

                string attribute = xmlElement.GetAttribute("Source");

 

                TreeViewItem treeViewItem = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;

 

                if(attribute != null && attribute.Length > 0 && source.EndsWith(attribute))

                {

                    if(treeViewItem != null && !treeViewItem.IsSelected)

                    {

                        treeViewItem.IsSelected = true;

                    }

 

                    return true;

                }

 

                if(treeViewItem != null)

                {

                    bool bIsExpanded = treeViewItem.IsExpanded;

 

                    treeViewItem.IsExpanded = true;

 

                    if(treeViewItem.HasItems && FindItemToSelect(treeViewItem, source))

                    {

                        return true;

                    }

 

                    treeViewItem.IsExpanded = bIsExpanded;

                }

            }

 

            return false;

        }

 

        #endregion

    }

}

 

 

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="도움말 윈도우 사용하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <DockPanel>

        <Menu DockPanel.Dock="Top"

            FontFamily="나눔고딕코딩"

            FontSize="16">

            <MenuItem Header="_Help">

                <MenuItem Header="_Help..." Command="Help" />

            </MenuItem>

        </Menu>

        <TextBox AcceptsReturn="True" />

    </DockPanel>

    <Window.CommandBindings>

        <CommandBinding Command="Help" Executed="ExecuteHelp" />

    </Window.CommandBindings>

</Window>

 

 

MainWindow.cs

 

 

using System.Windows;

using System.Windows.Input;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Help 실행하기 - ExecuteHelp(sender, e)

 

        /// <summary>

        /// Help 실행하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void ExecuteHelp(object sender, ExecutedRoutedEventArgs e)

        {

            HelpWindow helpWindow = new HelpWindow();

 

            helpWindow.Owner = this;

            helpWindow.Title = "도움말";

 

            helpWindow.Show();

        }

 

        #endregion

    }

}

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요