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

TestProject.zip
다운로드

▶ ProductControl.xaml

<UserControl x:Class="TestProject.ProductControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
    Width="300"
    Height="280"
    FontFamily="나눔고딕코딩"
    FontSize="12">    
    <Grid>
        <StackPanel Margin="10">
            <StackPanel
                HorizontalAlignment="Center"
                Orientation="Horizontal"
                Margin="0 0 0 10">
                <TextBlock
                    VerticalAlignment="Center"
                    Text="Product Name :" />
                <dxe:TextEdit
                    Margin="5 0 0 0"
                    VerticalAlignment="Center"
                    IsReadOnly="True"
                    EditValue="{Binding Path=ProductName, Mode=OneWay}" />
            </StackPanel>
            <dx:GroupFrame
                MinWidth="300"
                Header="New Value Properties">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*"    />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Margin="5"
                        Text="Country : " />
                    <dxe:TextEdit x:Name="countryTextEdit" Grid.Row="0" Grid.Column="1" 
                        VerticalAlignment="Center"
                        Margin="5"
                        Width="150"
                        Height="25"
                        EditValue="{Binding Path=Country, Mode=TwoWay}" />
                    <TextBlock Grid.Row="1" Grid.Column="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Margin="5"
                        Text="City : " />
                    <dxe:TextEdit x:Name="cityTextEdit" Grid.Row="1" Grid.Column="1"
                        VerticalAlignment="Center"
                        Margin="5"
                        Width="150"
                        Height="25"
                        EditValue="{Binding Path=City, Mode=TwoWay}" />
                    <TextBlock Grid.Row="2" Grid.Column="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Margin="5"
                        Text="Quantity : " />
                    <dxe:TextEdit x:Name="quantityTextEdit" Grid.Row="2" Grid.Column="1"
                        VerticalAlignment="Center"
                        Margin="5"
                        Width="150"
                        Height="25"
                        EditValue="{Binding Path=Quantity, Mode=TwoWay}" />
                    <TextBlock Grid.Row="3" Grid.Column="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Margin="5"
                        Text="Unit Price : " />
                    <dxe:SpinEdit x:Name="unitPriceSpinEdit" Grid.Row="3" Grid.Column="1"
                        VerticalAlignment="Center"
                        Margin="5"
                        Width="150"
                        Height="25"
                        EditValue="{Binding Path=UnitPrice, Mode=TwoWay, Converter={StaticResource StringToIntegerValueConverterKey}}" />
                    <TextBlock Grid.Row="4" Grid.Column="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Margin="5"
                        Text="Product ID : " />
                    <dxe:SpinEdit x:Name="idSpinEdit" Grid.Row="4" Grid.Column="1"
                        VerticalAlignment="Center"
                        Margin="5"
                        Width="150"
                        Height="25"
                        EditValue="{Binding Path=ID, Mode=TwoWay, Converter={StaticResource StringToIntegerValueConverterKey}}" />
                </Grid>
            </dx:GroupFrame>          
        </StackPanel>
    </Grid>
</UserControl>

 

728x90

 

▶ ProductControl.xaml.cs

using System.Windows.Controls;

namespace TestProject
{
    /// <summary>
    /// 제품 컨트롤
    /// </summary>
    public partial class ProductControl : UserControl
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - ProductControl()

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

        #endregion
    }
}

 

▶ ProductListViewModel.cs

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;

using DevExpress.Xpf.Mvvm;

namespace TestProject
{
    /// <summary>
    /// 제품 리스트 뷰 모델
    /// </summary>
    public class ProductListViewModel : ViewModelBase 
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 제품 컬렉션
        /// </summary>
        private ObservableCollection<Product> productCollection = new ObservableCollection<Product>();

        /// <summary>
        /// 제품 폼 보여주기 명령
        /// </summary>
        private ICommand showProductFormCommand;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 제품 컬렉션 - ProductCollection

        /// <summary>
        /// 제품 컬렉션
        /// </summary>
        public ObservableCollection<Product> ProductCollection
        {
            get
            {
                return this.productCollection;
            }
        }

        #endregion
        #region 제품 폼 보여주기 명령 - ShowProductFormCommand

        /// <summary>
        /// 제품 폼 보여주기 명령
        /// </summary>
        public ICommand ShowProductFormCommand
        {
            get
            {
                if(this.showProductFormCommand == null)
                {
                    this.showProductFormCommand = new DelegateCommand<string>(OnShowProductFormCommandExecute);
                }

                return this.showProductFormCommand;
            }
        }

        #endregion
        #region 대화 상자 서비스 - DialogService

        /// <summary>
        /// 대화 상자 서비스
        /// </summary>
        public IDialogService DialogService
        {
            get
            {
                return GetService<IDialogService>();
            }
        }

        #endregion

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

        #region 생성자 - ProductListViewModel()

        /// <summary>
        /// 생성자
        /// </summary>
        public ProductListViewModel() : base()
        {
            this.productCollection.Add(new Product() { ID = 1000, ProductName = "Chang"         , Country = "UK"     , City = "Cowes"         , UnitPrice = 19, Quantity = 10 });
            this.productCollection.Add(new Product() { ID = 1001, ProductName = "Gravad lax"    , Country = "Italy"  , City = "Reggio Emilia" , UnitPrice = 12, Quantity = 16 });
            this.productCollection.Add(new Product() { ID = 1002, ProductName = "Ravioli Angelo", Country = "Brazil" , City = "Rio de Janeiro", UnitPrice = 19, Quantity = 12 });
            this.productCollection.Add(new Product() { ID = 1003, ProductName = "Tarte au sucre", Country = "Germany", City = "QUICK-Stop"    , UnitPrice = 22, Quantity = 50 });
            this.productCollection.Add(new Product() { ID = 1004, ProductName = "Steeleye Stout", Country = "USA"    , City = "Reggio Emilia" , UnitPrice = 18, Quantity = 20 });
            this.productCollection.Add(new Product() { ID = 1005, ProductName = "Pavlova"       , Country = "Austria", City = "Graz"          , UnitPrice = 21, Quantity = 52 });
            this.productCollection.Add(new Product() { ID = 1006, ProductName = "Longlife Tofu" , Country = "USA"    , City = "Boise"         , UnitPrice = 7 , Quantity = 120});
            this.productCollection.Add(new Product() { ID = 1007, ProductName = "Alice Mutton"  , Country = "Mexico" , City = "Meéxico D.F."   , UnitPrice = 21, Quantity = 15 });
            this.productCollection.Add(new Product() { ID = 1008, ProductName = "Alice Mutton"  , Country = "Canada" , City = "Tsawwassen"    , UnitPrice = 44, Quantity = 16 });
        }

        #endregion

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

        #region 제품 폼 보여주기 명령 실행시 처리하기 - OnShowProductFormCommandExecute(parameter)

        /// <summary>
        /// 제품 폼 보여주기 명령 실행시 처리하기
        /// </summary>
        /// <param name="parameter">매개 변수</param>
        private void OnShowProductFormCommandExecute(string parameter)
        {
            if(string.IsNullOrEmpty(parameter))
            {
                return;
            }

            Product product = new Product() { ProductName = parameter };

            UICommand addProductUICommand = new UICommand()
            {
                Caption  = "Add",
                IsCancel = false,
                IsDefault = true
            };

            UICommand cancelProductUICommand = new UICommand()
            {
                Caption   = "Cancel",
                IsDefault = false,
                IsCancel  = true
            };

            UICommand resultUICommand = DialogService.ShowDialog(new List<UICommand>() { addProductUICommand, cancelProductUICommand}, "Add New Product", product);

            if(resultUICommand == addProductUICommand)
            {
                this.productCollection.Add(product);
            }
        }

        #endregion
    }
}

 

▶ ProductNameEventArgsConverter.cs

using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Mvvm.UI;

namespace TestProject
{
    /// <summary>
    /// 제품명 이벤트 인자 변환자
    /// </summary>
    public class ProductNameEventArgsConverter : IEventArgsConverter
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 변환하기 - Convert(e)

        /// <summary>
        /// 변환하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        /// <returns>변환 값</returns>
        public object Convert(object e)
        {
            string productName = (e as ProcessNewValueEventArgs).DisplayText;

            return productName;
        }

        #endregion
    }
}

 

▶ StringToIntegerValueConverter.cs

using System;
using System.Windows.Data;
using System.Globalization;

namespace TestProject
{
    /// <summary>
    /// 문자↔정수 값 변환자
    /// </summary>
    public class StringToIntegerValueConverter : IValueConverter
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 변환하기 - Convert(value, targetType, parameter, cultureInfo)

        /// <summary>
        /// 변환하기
        /// </summary>
        /// <param name="value">값</param>
        /// <param name="targetType">타겟 타입</param>
        /// <param name="parameter">매개 변수</param>
        /// <param name="cultureInfo">CultureInfo 객체</param>
        /// <returns>변환 값</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
        {
            return (int)value;
        }

        #endregion
        #region 역변환하기 - ConvertBack(value, targetType, parameter, cultureInfo)

        /// <summary>
        /// 역변환하기
        /// </summary>
        /// <param name="value">값</param>
        /// <param name="targetType">타겟 타입</param>
        /// <param name="parameter">매개 변수</param>
        /// <param name="cultureInfo">CultureInfo 객체</param>
        /// <returns>역변환 값</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
        {
            return value.ToString();
        }

        #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"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:local="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="LookUpEdit 클래스 : 신규 값 처리하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.DataContext>
        <local:ProductListViewModel />
    </Window.DataContext>
    <Grid>
        <dxg:LookUpEdit x:Name="lookUpEdit"
            ItemsSource="{Binding Path=ProductCollection}"
            Width="200"
            Height="25"
            ValueMember="ID" 
            DisplayMember="ProductName"
            AddNewButtonPlacement="EditBox"
            AutoComplete="True"
            IncrementalFiltering="True"
            ImmediatePopup="True"
            AutoPopulateColumns="True"
            IsPopupAutoWidth="False">
            <dxmvvm:Interaction.Triggers>
                <dxmvvm:EventToCommand
                    PassEventArgsToCommand="True"
                    Command="{Binding ShowProductFormCommand}"
                    EventName="ProcessNewValue"
                    SourceName="lookUpEdit">
                    <dxmvvm:EventToCommand.EventArgsConverter>
                        <local:ProductNameEventArgsConverter />
                    </dxmvvm:EventToCommand.EventArgsConverter>
                </dxmvvm:EventToCommand>
            </dxmvvm:Interaction.Triggers>
        </dxg:LookUpEdit>               
    </Grid>
    <dxmvvm:Interaction.Behaviors>
        <dx:DialogService DialogWindowStartupLocation="CenterOwner">
            <dx:DialogService.ViewTemplate>
                <DataTemplate>
                    <local:ProductControl />
                </DataTemplate>
            </dx:DialogService.ViewTemplate>
            <dx:DialogService.DialogStyle>
                <Style TargetType="dx:DXDialogWindow">
                    <Setter Property="Width"  Value="340" />
                    <Setter Property="Height" Value="340" />
                </Style>
            </dx:DialogService.DialogStyle>
        </dx:DialogService>
    </dxmvvm:Interaction.Behaviors>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;

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

        #region 생성자 - MainWindow()

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

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

댓글을 달아 주세요