1

助けてくれてありがとう。コードからcelleditingtemplate(datatemplate)にあるusercontrolのバインディングを設定する必要があります。つまり、同じデータテンプレートを指すcelleditingtemplateを持つ2つのdatatemplate列を持つグリッドがあります。ユーザーが編集しているセルに基づいて、celleditingtemplateのバインドを動的に変更する必要があります。どんな助けでも大歓迎です。

ありがとう

これがサンプルコードです。これは別のリソースファイルにあります

<DataTemplate x:Key="TextCellEditingTemplate">        
          <UserControls:TextControl HorizontalAlignment="Left"/>    
</DataTemplate>

これは、バインディングを設定する必要があるページの背後にあるコードです。

private void datagrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)        
{            
var row = e.Row;            
var column = e.Column as DataGridTemplateColumn;            
if (column != null)            
  {                
//sets the template based on the dataelement                
column.CellEditingTemplate = UserControlFactory.GetCellEditingTemplate(((row.DataContext) as CollectionData).DataElement);                                 
  }        
}
4

1 に答える 1

0

それを見つけた。

private void datagrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
    {
        e.EditingElement.DataContext = CollectionDataToEdit;
    }

ありがとう

于 2011-03-10T18:16:31.743 に答える