첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
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:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" 
    SizeToContent="WidthAndHeight"
    Title="에디터 데이터 바인딩 하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"    />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0"
            VerticalAlignment="Center"
            Margin="10"
            Text="Product Name : " />
        <dxe:TextEdit x:Name="textEdit" Grid.Row="0" Grid.Column="1"
            VerticalAlignment="Center"
            Margin="10"
            Width="150"
            Height="25"
            EditValue="{Binding ProductName}" />
        <TextBlock Grid.Row="1" Grid.Column="0"
            VerticalAlignment="Center"
            Margin="10"
            Text="Unit Price : " />
        <dxe:SpinEdit x:Name="spinEdit" Grid.Row="1" Grid.Column="1"
            VerticalAlignment="Center"
            Margin="10"
            Width="150"
            Height="25"
            EditValue="{Binding UnitPrice}" />
        <TextBlock Grid.Row="2" Grid.Column="0"
            VerticalAlignment="Center"
            Margin="10"
            Text="Category : " />
        <dxe:ComboBoxEdit x:Name="comboBoxEdit" Grid.Row="2" Grid.Column="1"
            Margin="10"
            Width="150"
            Height="25"
            ValueMember="CategoryID"
            DisplayMember="CategoryName"
            EditValue="{Binding CategoryID}"
            IsTextEditable="False" />
        <StackPanel Grid.Row="3" Grid.Column="1"
            Margin="10"
            Orientation="Horizontal">
            <Button x:Name="previousButton"
                Width="70"
                Height="25"
                IsEnabled="False"
                Content="Previous"
                Click="previousButton_Click" />
            <Button x:Name="nextButton"
                Margin="5 0 0 0"
                Width="70"
                Height="25"
                Content="Next"
                Click="nextButton_Click" />
        </StackPanel>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;

using TestProject.NorthwindDataSetTableAdapters;

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

        #region Field

        /// <summary>
        /// 제품 데이터 테이블
        /// </summary>
        private NorthwindDataSet.ProductsDataTable productsDataTable;

        /// <summary>
        /// 현재 레코드
        /// </summary>
        private int currentRecord;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

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

            this.productsDataTable = new ProductsTableAdapter().GetData();

            this.currentRecord = 0;

            DataContext = this.productsDataTable[currentRecord];

            this.comboBoxEdit.ItemsSource = new CategoriesTableAdapter().GetData();
        }

        #endregion

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

        #region Previous 버튼 클릭시 처리하기 - previousButton_Click(sender, e)

        /// <summary>
        /// Previous 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void previousButton_Click(object sender, RoutedEventArgs e)
        {
            this.currentRecord--;

            UpdateData();

            UpdateButtonState();
        }

        #endregion
        #region Next 버튼 클릭시 처리하기 - nextButton_Click(sender, e)

        /// <summary>
        /// Next 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            this.currentRecord++;

            UpdateData();

            UpdateButtonState();
        }

        #endregion

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

        #region 데이터 갱신하기 - UpdateData()

        /// <summary>
        /// 데이터 갱신하기
        /// </summary>
        private void UpdateData()
        {
            DataContext = this.productsDataTable[currentRecord];
        }

        #endregion
        #region 버튼 상태 갱신하기 - UpdateButtonState()

        /// <summary>
        /// 버튼 상태 갱신하기
        /// </summary>
        private void UpdateButtonState()
        {
            this.previousButton.IsEnabled = this.currentRecord != 0;
            this.nextButton.IsEnabled     = this.currentRecord != this.productsDataTable.Rows.Count - 1;
        }

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

댓글을 달아 주세요