0

I have a WPF DataGrid bound to a ViewModel which has a date field. I wanted to change date field editing from using a TextBox to Calendar or DatePicker instead. I followed the below link exactly. But, for some reason, I am not able to see the Calendar next to the DatePicker's TextBox. It's confusing. I am copy pasting my code below (source):

<Grid.Resources>            
    <DataTemplate x:Key="DateTemplate">
        <TextBox IsReadOnly="False" Text="{Binding TestDate}"></TextBox>
    </DataTemplate>

    <DataTemplate x:Key="EditingDateTemplate">
        <DatePicker SelectedDate="{Binding TestDate}" />
    </DataTemplate>
</Grid.Resources>

 <DataGridTemplateColumn Header="Test Date" IsReadOnly="False" CellTemplate="{StaticResource DateTemplate}" CellEditingTemplate="{StaticResource EditingDateTemplate}" Width="120">
4

1 回答 1

0

The reason is that the textbox covers whole area of the datagrid cell. To enter to the cell editing mode you need to double click on the cell but you can't because you always hit the textbox instead. You can check it by setting margin="5" for your textbox in the DateTemplate and then try to double click on the border area of the cell. Just set the IsHitTestVisible="False" property for your text box:

<DataTemplate x:Key="DateTemplate">
    <TextBox IsReadOnly="False" Text="{Binding TestDate}" IsHitTestVisible="False"></TextBox>
</DataTemplate>
<DataTemplate x:Key="EditingDateTemplate">
    <DatePicker SelectedDate="{Binding TestDate}" />
</DataTemplate>
于 2013-05-23T10:47:07.633 回答