バージョン

Converter プロパティ (Field)

このフィールドによって表される各セルの値を変換するために使用するコンバーターを取得または設定します。
シンタックス
'宣言
 
Public Property Converter As IValueConverter
public IValueConverter Converter {get; set;}
解説

このオブジェクトは、DataTypeEditAsTypeResolved の間で CellCell.Value を変換するために使用されます。変換値は、セルの Cell.ConvertedValue プロパティまたは DataRecordDataRecord.GetCellValue メソッドおよび DataRecord.SetCellValue メソッドからアクセスできます。

この Field の EditAsType を変更するには、その Settings.FieldSettings.EditAsType プロパティを設定します。

注: Field の DataType が EditAsTypeResolved に一致する場合でさえ、コンバーターの Convert メソッドと ConvertBack メソッドが呼び出されます。

使用例
Imports Infragistics.Windows.DataPresenter

Class Window1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

    End Sub

    Private Sub XamDataGrid1_InitializeRecord(ByVal sender As Object, ByVal e As Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs) Handles XamDataGrid1.InitializeRecord
        Dim dr As DataRecord

        If (e.Record.GetType() Is GetType(DataRecord)) Then
            dr = CType(e.Record, DataRecord)
            dr.Cells("VIP").Value = False
        End If
    End Sub
End Class

Public Class BoolToYesNoConverter : Implements IValueConverter

    Public Shared ReadOnly Instance As New BoolToYesNoConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert

        If (targetType Is GetType(String)) Then
            If (value Is Nothing) Then
                Return "No"
            End If

            If (value.GetType() Is GetType(Boolean)) Then
                If (CType(value, Boolean) = True) Then
                    Return "Yes"
                End If

            End If

            Return "No"
        End If


        Return value

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack

        If (targetType Is GetType(Boolean)) Then
            If (value Is Nothing) Then
                Return False
            End If

            If (value.GetType() Is GetType(String)) Then
                If (String.Compare(CType(value, String), "yes", True, culture) = 0) Then
                    Return True
                End If
            End If

            Return False
        End If

        Return value

    End Function
End Class
using Infragistics.Windows.DataPresenter;

namespace Snippet_app_1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            this.XamDataGrid1.InitializeRecord += new EventHandler<Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs>(OnInitializeRecord);
        }

        void OnInitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
        {
            DataRecord dr = e.Record as DataRecord;

            if (dr != null)
                dr.Cells["VIP"].Value = false;
            
        }
    }

    public class BoolToYesNoConverter : IValueConverter
    {
        public static BoolToYesNoConverter Instance = new BoolToYesNoConverter();

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(string) )
            {
                if (value is bool)
                {
                    if ((bool)value == true)
                        return "Yes";
                }

                return "No";
            }

            return value;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(bool))
            {
                if (value is string)
                {
                    if (string.Compare((string)value, "yes", true, culture) == 0)
                        return true;
                }

                return false;
            }
            return value;
        }

        #endregion
    }

}
<Window x:Class="Snippet_app_1.Window1"
    
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
xmlns:igDP="http://infragistics.com/DataPresenter"
    
xmlns:igEditors="http://infragistics.com/Editors"
    
xmlns:igWindows="http://infragistics.com/Windows"
    
xmlns:igThemes="http://infragistics.com/Themes"
    
xmlns:sys="clr-namespace:System;assembly=mscorlib"
    
xmlns:local="clr-namespace:Snippet_app_1"
    
Title="Window1" Height="300" Width="300">
    
<Grid>
        
<igDP:XamDataGrid BindToSampleData="True" x:Name="XamDataGrid1">
             
<igDP:XamDataGrid.FieldLayouts>
                
<igDP:FieldLayout>
                    
<igDP:FieldLayout.Fields>
                        
<igDP:UnboundField Name="VIP" Label="VIP Yes/No" 
                                           
DataType="{x:Type sys:Boolean}"
                                           
Converter="{x:Static local:BoolToYesNoConverter.Instance}">
                            
<igDP:Field.Settings>
                                
<igDP:FieldSettings EditAsType="{x:Type sys:String}"/>
                            
</igDP:Field.Settings>
                        
</igDP:UnboundField>
                    
</igDP:FieldLayout.Fields>
                
</igDP:FieldLayout>
            
</igDP:XamDataGrid.FieldLayouts>
        
</igDP:XamDataGrid>
    
</Grid>
</Window>
参照