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

▶ 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:s="clr-namespace:System;assembly=mscorlib"
    xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
    xmlns:local="clr-namespace:TestProject"
    Width="600"
    Height="450"
    Title="언바운드 데이터 제공하기">
    <Window.Resources>
        <xcdg:DataGridCollectionViewSource x:Key="DataGridCollectionViewSourceKey"
            Source="{Binding Source={x:Static Application.Current}, Path=ProductTable}">
            <xcdg:DataGridCollectionViewSource.ItemProperties>
                <xcdg:DataGridUnboundItemProperty Name="TotalUnitValue" DataType="{x:Type s:Double}" QueryValue="totalUnitValueDataGridUnboundItemProperty_QueryValue" />
            </xcdg:DataGridCollectionViewSource.ItemProperties>
        </xcdg:DataGridCollectionViewSource>
        <local:CurrencyConverter x:Key="CurrencyConverterKey"/>
    </Window.Resources>
    <Grid>
        <xcdg:DataGridControl x:Name="dataGridControl"
            ItemsSource="{Binding Source={StaticResource DataGridCollectionViewSourceKey}}">
            <xcdg:DataGridControl.Columns>
                <xcdg:Column FieldName="TotalUnitValue" Title="Total Inventory">
                    <xcdg:Column.CellContentTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Converter={StaticResource CurrencyConverterKey}}" />
                        </DataTemplate>
                    </xcdg:Column.CellContentTemplate>
                </xcdg:Column>
                <xcdg:Column FieldName="Photo" Visible="False" />
            </xcdg:DataGridControl.Columns>
        </xcdg:DataGridControl>
    </Grid>
</Window>

 

728x90

 

▶ C#

using System;
using System.Data;

using Xceed.Wpf.DataGrid;

#region Total Unit Value 데이터 그리드 언바운드 항목 속성 값 질의시 처리하기 - totalUnitValueDataGridUnboundItemProperty_QueryValue(sender, e)

/// <summary>
/// Total Unit Value 데이터 그리드 언바운드 항목 속성 값 질의시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void totalUnitValueDataGridUnboundItemProperty_QueryValue(object sender, DataGridItemPropertyQueryValueEventArgs e)
{
    DataRowView dataRowView = e.Item as DataRowView;

    if(dataRowView != null )
    {
        if(dataRowView["UnitsInStock"] != DBNull.Value)
        {
            e.Value = (double)((short)dataRowView["UnitsInStock"] * (decimal)dataRowView["UnitPrice"]);
        }
    }
}

#endregion

※ 전체 실행 가능한 코드가 아닌 일부 발췌된 코드이다.

728x90
그리드형(광고전용)
Posted by icodebroker
,