我有一个带有datagrid的wpf应用程序,它有数据贴纸,它有日期值。如果用户更改日期,则运行一些逻辑并显示一个弹出窗口作为selectionChangedEvent hanlder代码的一部分。如果他们在弹出窗口中选择“否”,那么我想重置日期......无法计算此部分
MyXaml
<%= link_to "bid on this job",
job_path(@job) unless current_user.job_id == @job? %>
代码
<DataGridTemplateColumn Header="Start Date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker Name="StartDate" SelectedDate="{Binding StartDate}" BorderThickness="0" SelectedDateChanged="StartDate_SelectedDateChanged">
<DatePicker.Resources>
<Style TargetType="DatePickerTextBox">
<Setter Property="IsReadOnly" Value="True"/>
<Setter Property="IsEnabled" Value="False"/>
</Style>
</DatePicker.Resources>
</DatePicker>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
更新:问题是同一个日期选择器被触发的另外两个事件导致弹出窗口显示三次。这也发生在加载时
答案 0 :(得分:1)
您可以使用Boolean
变量临时暂停事件处理程序实际执行某些操作,例如:
Private _handleEvent As Boolean = True
Private Sub ValidateDateChanged(sender As Object, e As SelectionChangedEventArgs)
If _handleEvent And MessageBoxResult.No = MessageBox.Show("Yes to Continue with the change",
vbApplicationModal + MsgBoxStyle.Information, MessageBoxButton.YesNo) Then
Dim dp As DatePicker = CType(sender, DatePicker)
_handleEvent = False
dp.SelectedDate = CType(e.RemovedItems(0), Date?)
_handleEvent = True
End If
End Sub