2009-07-22 2 views
0

WPF DataGrid (매우 새로운 WPF)을 구현 중입니다. staticresources를 사용하여 ComboBoxColumn을 바인딩하는 방법을 보여주는 자습서를 따라했습니다. 그러나, 내 datagrid에있는 몇 가지 열에 대한 데이터 바인딩은 런타임까지 알 수 없습니다.WPF Toolkit - Datagrid - DynamicResource가있는 ComboboxColumn 바인딩

이 때문에 staticresource로 바인딩 할 수 없습니다. DataGridComboBoxColumn을 데이터 바인딩하는 다른 방법이 있습니까? ASP.NET에서 우리는 rowdatabound 코드를 사용하여이 작업을 수행 할 수 있고 동적으로 열의 내용을 만들 수 있음을 알고 있습니다. 그러나 WPF에서는 모든 것이 리소스를 통해 이루어지듯합니다.

어떻게 DataGrid에서 동적 리소스를 사용하여 데이터 바인딩을 할 수 있습니까?

감사합니다.

답변

0

바인딩을 동적으로 설정할 수 있습니다. 이와 비슷한 것 (이 코드는 격자보기 열을 만들고 동적 바인딩을 할당 함)

 private void AddColumn(GridView view, Field fld) 
     { 
      GridViewColumn col = new GridViewColumn(); 
      col.Header = fld.Label; 
      Binding bnd = new Binding(); 
      switch (fld.FieldType) 
      { 
       case FieldType.DateTime: 
       bnd.Converter = new DateTimeToDateStringConverter(); 
       break; 
// or some other converters 
      } 
      bnd.Path = new PropertyPath(string.Format("Fields[{0}]", 
    _table._fields.IndexOf(fld))); // the string matches what you would use in XAML 
      col.DisplayMemberBinding = bnd; 
      view.Columns.Add(col); 
     }