1
WPF DataGrid의 CellEditEnding 이벤트를 사용하여 데이터의 유효성을 검사하고 다른 계산을 수행합니다. TextBoxes 및 DatePickers DataGridTemplateColumns 있습니다. 여기CellEditEnding 이벤트를 사용하여 WPF DataGrid에서 DatePicker 값 확인
내가 이벤트 핸들러
private void OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.EditAction == DataGridEditAction.Cancel) return;
DataGridCellEditEndingCommandParameter p = new DataGridCellEditEndingCommandParameter();
if (e.Column != null)
{
p.BindingPropertyName = e.Column.SortMemberPath;
if (e.Column.Header != null)
p.ColumnHeaderName = e.Column.Header.ToString();
}
TextBox t = e.EditingElement as TextBox;
if (t != null)
p.EndingElementValue = t.Text;
//else if (e.EditingElement as DatePicker)
if (e.Row != null) p.RowItem = e.Row.Item;
p.EventArgs = e;
p.Sender = sender as DataGrid;
CommandParameter = p;
ExecuteCommand();
}
I는 사용자가 입력 한 값, 널 (null) 결과가 DatePicker에서 편집 할 때 비록 DatePicker에서의 같은 일을 읽을 수있는 텍스트 상자로 EditingElement 변환하고 호출하는 방법입니다. I는 DatePicker에서의 값을 변경 한 후 EditingElement을 검사하면
<DataGridTemplateColumn x:Name="fxFwd" Header="Value Date" Width="70" SortMemberPath = "fwFwdDate" CanUsersort = "True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path= fxFwdDate,
ConverterCulture={x:Static gl:CultureInfo.CurrentCulture},
StringFormat=\{0:d\}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Path=fxFwdDate,
ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}, Mode=TwoWay,
ValidatesOnExceptions=true, NotifyOnValidationError=true}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
은 그것을 대신하여 ContentPresenter DatePicker에서로 수신되고있다. 당신의 DatePicker
제어에 사전