你必須重寫PrepareCellForEdit
在DataGridTemplateColumn
如下:
public class DataGridDateColumn:DataGridTemplateColumn
{
protected override object PrepareCellForEdit(FrameworkElement editingElement,
RoutedEventArgs editingEventArgs)
{
editingElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
return base.PrepareCellForEdit(editingElement, editingEventArgs);
}
}
XAML
<Custom:DataGrid x:Name="dgData" SelectionUnit="Cell" AutoGenerateColumns="False" CanUserAddRows="False">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding Subject}" Header="Subject" Width="*"/>
<Custom:DataGridTextColumn Binding="{Binding RaisedBy}" Header="Raised By" Width="100"/>
<DatePickerDGWPF:DataGridDateColumn Header="Raised On" Width="250">
<DatePickerDGWPF:DataGridDateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding RaisedOn}" />
</DataTemplate>
</DatePickerDGWPF:DataGridDateColumn.CellTemplate>
<DatePickerDGWPF:DataGridDateColumn.CellEditingTemplate>
<DataTemplate>
<Custom:DatePicker SelectedDate="{Binding RaisedOn}"/>
</DataTemplate>
</DatePickerDGWPF:DataGridDateColumn.CellEditingTemplate>
</DatePickerDGWPF:DataGridDateColumn>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
您可以顯示XAML?這將幫助我們重現並幫助您解決問題。 – keyle 2011-03-03 04:20:06