【问题标题】:WPF create editable cell in ListViewWPF在ListView中创建可编辑单元格
【发布时间】:2020-07-02 17:30:59
【问题描述】:
我一直在寻找一种在<GridViewColumn> 中创建可编辑单元格的方法,我找到的答案参考<GridViewColumn.CellTemplate> 但是当我尝试使用这种方法时,我得到了这个错误Error XLS0415 The attachable property 'CellTemplate' was not found in type 'GridViewColumn'. Test MainWindow.xaml 26,我有没有找到其他潜在的解决方案。我需要有一个可编辑的 TextBox 和一个可编辑的 DatePicker。
【问题讨论】:
标签:
wpf
datagrid
wpf-controls
【解决方案1】:
CellTemplate 没有可附加的属性,但是通过使用找到了解决方案
<DataTemplate x:Key="TextCell">
<TextBox Text={Binding [DataName]}"/>
</DataTemplate>
<DataTemplate x:Key="DateCell">
<DatePicker Text{Binding [OtherDataName]}"/>
</DataTemplate>
然后在这里调用
<GridViewColumn Header="Foo" width="xx" CellTemplate="{StaticResource TextCell}"/>
<GridViewColumn Header="Bar" width="xx" CellTemplate="{StaticResource DateCell}"/>