첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
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"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    Width="800"
    Height="600"
    Title="그리드 레이아웃 저장시 저장 속성 선택하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"   />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <dxg:GridControl x:Name="gridControl"
            Loaded="gridControl_Loaded">
            <dxg:GridControl.Columns>
                <dxg:GridColumn x:Name="colIssueName" FieldName="IssueName" Visible="True"  Width="100"                 />
                <dxg:GridColumn x:Name="colIssueType" FieldName="IssueType" Visible="True"  Width="80"                  />
                <dxg:GridColumn x:Name="colPrivate"   FieldName="IsPrivate" Visible="False" Width="20" Header="Private" />
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TableView />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <StackPanel
            Grid.Row="1"
            Margin="0 5 0 5"
            Orientation="Horizontal">
            <Button x:Name="saveLayoutButton"
                Margin="5 0 5 0"
                Padding="5"
                Content="Save Layout"
                Click="saveLayoutButton_Click" />
            <Button x:Name="restoreLayoutButton"
                Padding="5"
                Content="Restore Layout"
                Click="restoreLayoutButton_Click" />
        </StackPanel>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;

using DevExpress.Xpf.Core.Serialization;
using DevExpress.Xpf.Grid;

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

        #region 생성자 - MainWindow()

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

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 그리드 컨트롤 로드시 처리하기 - gridControl_Loaded(sender, e)

        /// <summary>
        /// 그리드 컨트롤 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void gridControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.gridControl.ItemsSource = new IssueList().GetData();

            foreach(GridColumn gridColumn in this.gridControl.Columns)
            {
                gridColumn.AddHandler(DXSerializer.AllowPropertyEvent, new AllowPropertyEventHandler(gridColumn_AllowProperty));
            }
        }

        #endregion
        #region 그리드 컬럼 속성 허용 처리하기 - gridColumn_AllowProperty(sender, e)

        /// <summary>
        /// 그리드 컬럼 속성 허용 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void gridColumn_AllowProperty(object sender, AllowPropertyEventArgs e)
        {
            e.Allow = e.DependencyProperty == GridColumn.ActualWidthProperty ||
                      e.DependencyProperty == GridColumn.FieldNameProperty   ||
                      e.DependencyProperty == GridColumn.VisibleProperty;
        }

        #endregion
        #region Restore Layout 버튼 클릭시 처리하기 - restoreLayoutButton_Click(sender, e)

        /// <summary>
        /// Restore Layout 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void restoreLayoutButton_Click(object sender, RoutedEventArgs e)
        {
            this.gridControl.RestoreLayoutFromXml("layout.xml");
        }

        #endregion
        #region Save Layout 버튼 클릭시 처리하기 - saveLayoutButton_Click(sender, e)

        /// <summary>
        /// Save Layout 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void saveLayoutButton_Click(object sender, RoutedEventArgs e)
        {
            this.gridControl.SaveLayoutToXml("layout.xml");
        }

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

댓글을 달아 주세요