2

这似乎有点微不足道,但我XamDataGrid在我的 WPF 应用程序中有一个我想自己设置它的列标题但不能。

绑定是到BindingList<DictionaryEntry>(不是那个.Net,但仍然只有KeyValue属性。

这些列被命名Key并且Value(如果我更改DictionaryEntry类中的属性名称,则更新),而我想在 XAML 中设置它们:(该FieldsLayout部分)

<igDP:XamDataGrid Grid.Row="1"
                  Grid.Column="0"
                  Name="ResultStructure"
                  DataSource="{Binding Path=VariablesDictionary, Mode=TwoWay, ValidatesOnExceptions=True}"
                  Theme="Aero"
                  GroupByAreaLocation="None"
                  IsEnabled="{Binding CanEditStructure}"
                  CellUpdating="ResultStructure_OnCellUpdating"
                  CellUpdated="ResultStructure_OnCellUpdated">
  <igDP:XamDataGrid.FieldLayoutSettings>
    <igDP:FieldLayoutSettings AllowClipboardOperations="All"
                              AllowFieldMoving="WithinLogicalRow"
                              AllowAddNew="True"
                              AddNewRecordLocation="OnBottom"
                              AllowDelete="True" />
  </igDP:XamDataGrid.FieldLayoutSettings>
  <igDP:XamDataGrid.FieldLayouts>
    <igDP:FieldLayout>
      <igDP:FieldLayout.Fields>
        <igDP:Field Name="Column" Tag="Column" Width="Auto" />
        <igDP:Field Tag="Variable" Name="Variable" Width="Auto" />
      </igDP:FieldLayout.Fields>
    </igDP:FieldLayout>
  </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

谢谢。

4

1 回答 1

4

这个问题有一个标签属性

<igDP:Field Name="propertyName" Label="Your custom column name" />

编辑 2

这是一个对我有用的完整示例(注意:您需要 AutoGenerateFields="False"),现在带有视图模型。

<Window x:Class="WpfApplication1.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"
        Title="Window1"
        Height="400"
        Width="600">
  <Grid>
    <igDP:XamDataGrid DataSource="{Binding SampleDataList}"
                      Theme="Aero"
                      GroupByAreaLocation="None">
      <igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:FieldLayoutSettings AllowClipboardOperations="All"
                                  AllowFieldMoving="WithinLogicalRow"
                                  AllowAddNew="True"
                                  AddNewRecordLocation="OnBottom"
                                  AutoGenerateFields="False"
                                  AllowDelete="True" />
      </igDP:XamDataGrid.FieldLayoutSettings>
      <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
          <igDP:FieldLayout.Fields>
            <igDP:Field Name="Sample1"
                        Label="Custom Label Spalte 1"
                        Width="Auto" />
            <igDP:Field Name="Sample2"
                        Label="Custom Label Spalte 2"
                        Width="Auto" />
          </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
      </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>
  </Grid>
</Window>

后面的代码和使用 BindingList 的视图模型

public partial class Window1 : Window
{
  public Window1() {
    this.DataContext = new SampleDataViewModel();
    this.InitializeComponent();
  }
}

public class SampleDataViewModel : DependencyObject
{
  public class SampleData : INotifyPropertyChanged
  {
    private string sample1;
    private string sample2;

    public string Sample1 {
      get { return this.sample1; }
      set {
        if (Equals(value, this.sample1)) {
          return;
        }
        this.sample1 = value;
        this.OnPropertyChanged("Sample1");
      }
    }

    public string Sample2 {
      get { return this.sample2; }
      set {
        if (Equals(value, this.sample2)) {
          return;
        }
        this.sample2 = value;
        this.OnPropertyChanged("Sample2");
      }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName) {
      var handler = this.PropertyChanged;
      if (handler != null) {
        handler(this, new PropertyChangedEventArgs(propertyName));
      }
    }
  }

  public static readonly DependencyProperty SampleDataListProperty =
    DependencyProperty.Register("SampleDataList", typeof(BindingList<SampleData>), typeof(Window1), new PropertyMetadata(default(BindingList<SampleData>)));

  public BindingList<SampleData> SampleDataList {
    get { return (BindingList<SampleData>)this.GetValue(SampleDataListProperty); }
    set { this.SetValue(SampleDataListProperty, value); }
  }

  public SampleDataViewModel() {
    this.SampleDataList = new BindingList<SampleData>();
    for (int i = 0; i < 10; i++) {
      var data = new SampleData();
      data.Sample1 = "Test sample Text " + i % 100;
      data.Sample2 = "Another Test " + i % 200;
      this.SampleDataList.Add(data);
    }
  }
}

希望有帮助

于 2012-11-19T15:30:17.247 回答