我的用户控件中有一个 telerik:RadGridView ,它有各种各样的 列和我有一个RadDatePicker,
<telerik:RadGridView Grid.Row="1"
Grid.Column="0"
AutoGenerateColumns="False"
AutoExpandGroups="True"
IsReadOnly="False"
ColumnWidth="*"
ItemsSource="{Binding DataModel.FlightDetailsList, Mode=TwoWay}"
IsFilteringAllowed="False"
IsSynchronizedWithCurrentItem="False"
SelectionMode="Single"
ShowGroupPanel="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Date of Travel *" DataMemberBinding="{Binding FlightDate}">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=FlightDate, Mode=OneWay, StringFormat=dd-MMM-yyyy}" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
<telerik:GridViewColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadDatePicker SelectedDate="{Binding Path=FlightDate, Mode=TwoWay, StringFormat=dd-MMM-yyyy, UpdateSourceTrigger=LostFocus}" DisplayFormat="Short" Culture="en-AU" />
</DataTemplate>
</telerik:GridViewColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
这里如果你看到我的收藏品FlightDetailsList是绑定到的数据 网格。 telerik:RadDatePicker绑定到FlightDate属性。
我想调用FlightDate属性的属性更改 我已订阅的viewmodel,
private void FlightDetailsListCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
var _obj = (e.NewItems[0] as FlightDtls);
if (_obj != null)
(e.NewItems[0] as FlightDtls).PropertyChanged += new PropertyChangedEventHandler(FlightDtlsPropertyChanged);
}
}
private void FlightDtlsPropertyChanged(object sender, PropertyChangedEventArgs e)
{
var data = sender as FlightDtls;
if (data != null && string.Equals(e.PropertyName, "FlightDate", StringComparison.InvariantCultureIgnoreCase) && IsValidateFltDt && (DateTime.Now.Date - data.FlightDate.Value.Date).TotalDays > 2)
{
CommonMethods.ShowAlertMessage("The Date of Travel in Flight Routing must be no less than 2 days!", MessageBoxImage.Exclamation);
}
}
每当我习惯使用更改日期时,我都面临着问题 datepicker propertychanged事件是trigerring两次。而如果我 我正在通过键盘编辑日期甚至是一次作为 预期。如何在选择时避免双重调用 datepicker。
答案 0 :(得分:1)
将列的类型更改为GridViewColumn
:
<telerik:GridViewColumn Header="Date of Travel *">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=FlightDate, Mode=OneWay, StringFormat=dd-MMM-yyyy}" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
<telerik:GridViewColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadDatePicker SelectedDate="{Binding Path=FlightDate, Mode=TwoWay, StringFormat=dd-MMM-yyyy, UpdateSourceTrigger=LostFocus}" DisplayFormat="Short" Culture="en-AU" />
</DataTemplate>
</telerik:GridViewColumn.CellEditTemplate>
</telerik:GridViewColumn>