Cannot edit cells of my DataGrid WPF Framework 4.5

后端 未结 1 1511
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 02:51

My ObservableCollection has three items, and the rows are consistently shown in the datagrid. I cannot turn into edit mode a single cell of my DataGrid. I tried click, click

相关标签:
1条回答
  • 2021-01-18 03:01

    You have placed TextBlock in cell template as well as in cell editing template. That's why you are not noticing any change on pressing F2 and double-clicking the cell since no matter what it will always be TextBlock which you can't edit.

    Either placed TextBox in your CellEditingTemplate like this -

    <DataGridTemplateColumn Header="Formulation" Width="100" IsReadOnly="False">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormulationStr}" />
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
        <DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
                <TextBox Text="{Binding FormulationStr}" />
            </DataTemplate>
        </DataGridTemplateColumn.CellEditingTemplate>
    </DataGridTemplateColumn>
    

    Or either simply use the DataGridTextColumn in place of DataGridTemplateColumn which internally provides the support what are you trying to achive by the above code -

    <DataGridTextColumn Header="Formulation" Width="100" IsReadOnly="False" Binding="{Binding FormulationStr}" />
    
    0 讨论(0)
提交回复
热议问题