0
행의 다른 항목을 편집하거나 읽을 수있는 DataGrid가 있습니다. 난 단지 마음대로 읽게 될 필요가 단일 셀이 있다면 나는 내 선택의 열에 해당 템플릿을 적용하는 것보다템플릿 내의 요소 바인딩 변경
, 나는
<DataGrid.Resources>
<!-- the non-editing cell -->
<DataTemplate x:Key="ReadonlyCellTemplate">
<TextBlock Text="{Binding UserName}" />
</DataTemplate>
<!-- the editing cell -->
<DataTemplate x:Key="EditableCellTemplate">
<TextBox Text="{Binding UserName}" />
</DataTemplate>
</DataGrid.Resources>
같은 것을 사용하고 싶습니다.
<DataGridTemplateColumn CellTemplate="{StaticResource ReadonlyCellTemplate}" Header="User name">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<!-- the additional layer of content presenter -->
<ContentPresenter x:Name="Presenter" Content="{Binding}" ContentTemplate="{StaticResource ReadonlyCellTemplate}" />
<DataTemplate.Triggers>
<!-- dynamically switch the content template by IsEditable binding -->
<DataTrigger Binding="{Binding CreationFieldsEditable}" Value="True">
<Setter TargetName="Presenter" Property="ContentTemplate" Value="{StaticResource EditableCellTemplate}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
나는 템플릿 내부 {Binding UserName}
을 변경할 수 있도록하려면, 그래서 다른 컬럼에 템플릿을 적용 할 수 있습니다.
어떻게하면됩니까? 대신 템플릿을 확장해야
<DataTemplate x:Key="EditableCellTemplate">
<TextBox Text="{Binding UserName}" />
</DataTemplate>
의
Text = "{Binding UserName1}"대신 Text = "{Binding UserName2}"와 같은 바인딩 속성을 변경한다는 의미 인 경우 데이터 트리거를 사용하여 요소 자체를 변경하는 것이 일반적입니다. 조건을 잘 이해하면 솔루션에 대한 세부 정보를 제공 할 수 있습니다. –