【问题标题】:How to bind a xamDataGrid to a dataset in WPF4?如何将 xamDataGrid 绑定到 WPF4 中的数据集?
【发布时间】:2011-04-08 07:30:50
【问题描述】:

我正在开发 WPF4 应用程序并使用 DataSet 填充 xamDataGrid(来自 Infragistics)。 这是datagrid的xaml:

<igDP:XamDataGrid AutoFit="True" BindToSampleData="False" Grid.Column="1" HorizontalAlignment="Center" HorizontalContentAlignment="Center" IsUndoEnabled="True" Margin="0,0,0,40" Name="xamDataGridOrganization" SortRecordsByDataType="True" UndoLimit="2" UseLayoutRounding="True" VerticalAlignment="Bottom" VerticalContentAlignment="Center" Padding="0" Panel.ZIndex="1" MaxWidth="Infinity">
        <igDP:XamDataGrid.FieldSettings>
            <igDP:FieldSettings AllowEdit="False" AllowGroupBy="True"  AllowRecordFiltering="True" />
        </igDP:XamDataGrid.FieldSettings>
        <igDP:XamDataGrid.FieldLayouts>
            <igDP:FieldLayout>
                <igDP:FieldLayout.Fields>
                    <igDP:Field Name="Id" Label="Id"/>
                    <igDP:Field Name="OrganizationName" Label="Organization" />
                    <igDP:Field Name="EmailId" Label="Email Address" />
                </igDP:FieldLayout.Fields>
            </igDP:FieldLayout>
        </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>

现在我用来填充 xamDataGrid 的代码是:

var adcg = new OrganizationGridTableAdapter();
        AddressBookDataSet dbcg = new AddressBookDataSet();
        adcg.Fill(dbcg.OrganizationGrid);
        //xamDataGridIndividual.DataContext = dbc.Individual;
        xamDataGridOrganization.DataSource = dbcg.OrganizationGrid.DefaultView;

现在我的 DataTable OrganizationGrid 有以下字段:

  1. 身份证
  2. 组织名称
  3. EmailId

和其他一些领域..

我想更改标题中的文本和其他一些属性(宽度、文本大小).. 我该怎么做?

正如您在 XAML 代码中看到的那样,我定义了一个具有完全相同字段名称的 FieldLayout,我可以将我的 DataTable 中的列绑定到我定义的特定字段吗?

【问题讨论】:

    标签: wpf dataset field infragistics xamdatagrid


    【解决方案1】:

    您已经在使用标签更改标题。

     <igDP:Field Name="Id" Label="Id"/> 
    

    在上面的 xaml 中,您已经在数据源中绑定到“Id”。当它绑定时,它通过 Name 属性进行绑定。

    您可以使用 FieldSettings 通过样式来修改外观:

    <igDP:Field.Settings>
        <igDP:FieldSettings 
            EditorType="{x:Type Editors:XamDateTimeEditor}"
            EditorStyle="{StaticResource ResourceKey=styleDateTime}">
        </igDP:FieldSettings>
    </igDP:Field.Settings>
    

    风格是:

    <Style x:Key="styleDateTime" TargetType="{x:Type Editors:XamDateTimeEditor}">
        <Setter Property="Format" Value="dd-MMM-yyyy HH:mm:ss" />
        <Setter Property="ValueType" Value="{x:Type System:DateTime}"/>
    </Style>
    

    在 Infragistics 中搜索 XamDataGrid。

    This link might help

    【讨论】:

    • 要注意的一点,或者说我的代码的真正问题是我没有为数据表的所有列创建字段!因此它忽略了我的字段并自动生成所有字段!
    猜你喜欢
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多