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}
を変更できるようにしたいので、私は別の列にテンプレートを適用することができます。
どうすればよいですか?
Text = "{Binding UserName1}"の代わりにText = "{Binding UserName2}"などのバインディングプロパティを変更する場合は、データトリガーで要素自体を変更するのが普通です。 条件をよく理解していれば、解決策の詳細を説明することができます。 –