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

TestProject.zip
다운로드

▶ 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 x:Name="dockPanel" Margin="10" />
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;

using DevExpress.Xpf.NavBar;

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

        #region 생성자 - MainWindow()

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

            CreateNavBarControl();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region NavBarControl 뷰 항목 선택할 경우 처리하기 - navBarControl_View_ItemSelecting(sender, e)

        /// <summary>
        /// NavBarControl 뷰 항목 선택할 경우 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void navBarControl_View_ItemSelecting(object sender, NavBarItemSelectingEventArgs e)
        {
            if(e.NewItem.Content.ToString() == "Private")
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to select the 'Private' item?", "Confirm Dialog", MessageBoxButton.YesNo);

                e.Cancel = (messageBoxResult == MessageBoxResult.No);
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 그룹 1 생성하기 - CreateGroup1(navBarControl)

        /// <summary>
        /// 그룹 1 생성하기
        /// </summary>
        /// <param name="navBarControl">NavBarControl</param>
        private void CreateGroup1(NavBarControl navBarControl)
        {
            #region 그룹을 생성한다.

            NavBarGroup navBarGroup = new NavBarGroup();

            navBarGroup.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Image/folder.png"));
            navBarGroup.Header      = "Items";

            navBarControl.Groups.Add(navBarGroup);

            #endregion
            #region 항목 1을 생성한다.

            NavBarItem navBarItem1 = new NavBarItem();

            navBarItem1.Content = "Home";

            navBarGroup.Items.Add(navBarItem1);

            #endregion
            #region 항목 1을 생성한다.

            NavBarItem navBarItem2 = new NavBarItem();

            navBarItem2.Content = "Work";

            navBarGroup.Items.Add(navBarItem2);

            #endregion
            #region 항목 3을 생성한다.

            NavBarItem navBarItem3 = new NavBarItem();

            navBarItem3.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Image/private.png"));
            navBarItem3.Content     = "Private";

            Style style = new Style();

            style.Setters.Add(new Setter(NavBarViewBase.LayoutSettingsProperty, new LayoutSettings() { ImageDocking = Dock.Right }));

            navBarItem3.VisualStyle = style;

            navBarGroup.Items.Add(navBarItem3);

            #endregion
        }

        #endregion
        #region 그룹 2 생성하기 - CreateGroup2(navBarControl)

        /// <summary>
        /// 그룹 2 생성하기
        /// </summary>
        /// <param name="navBarControl">NavBarControl</param>
        private void CreateGroup2(NavBarControl navBarControl)
        {
            NavBarGroup navBarGroup = new NavBarGroup();

            navBarGroup.DisplaySource = DisplaySource.Content;
            navBarGroup.Header        = "Custom Content";

            StackPanel stackPanel = new StackPanel() { Orientation = Orientation.Horizontal };

            navBarGroup.Content = stackPanel;
            
            stackPanel.Children.Add(new TextBlock() { Text = "Selected Item : " });

            TextBlock textBlock = new TextBlock();
            Binding   binding   = new Binding("SelectedItem.Content");

            binding.Source = navBarControl;

            textBlock.SetBinding(TextBlock.TextProperty, binding);

            stackPanel.Children.Add(textBlock);

            navBarControl.Groups.Add(navBarGroup);
        }

        #endregion
        #region NavBarControl 생성하기 - CreateNavBarControl()

        /// <summary>
        /// NavBarControl 생성하기
        /// </summary>
        private void CreateNavBarControl()
        {
            NavBarControl navBarControl = new NavBarControl();

            this.dockPanel.Children.Add(navBarControl);

            DockPanel.SetDock(navBarControl, Dock.Left);

            CreateGroup1(navBarControl);
            CreateGroup2(navBarControl);

            navBarControl.View.ItemSelecting += navBarControl_View_ItemSelecting;
        }

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

댓글을 달아 주세요