我有这样的数据栏标题:
<datagridtemplatecolumn.headertemplate>
<datatemplate previewmouseleftbuttondown="TextBlock_DocumentsClick">
<stackpanel orientation="Vertical">
<textblock text="Doctor Name" previewmouseleftbuttondown="TextBlock_ReceptionsClick" name="DoctorName" />
<textbox name="SearchReceptionDoctor" width="120" tag="DoctorName" text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.RecDoctorNameFilter, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<textbox.inputbindings>
<keybinding key="Enter" command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.FilterReceptionsCommand}" commandparameter="{Binding Tag, ElementName=SearchReceptionDoctor}" />
</textbox.inputbindings>
</textbox>
</stackpanel>
</datatemplate>
</datagridtemplatecolumn.headertemplate>现在它运行良好,唯一的问题是,当我单击文本框时,我希望限制事件触发。是否有方法检查是否已单击文本框并防止触发事件的功能?以下是我的事件在代码后面的样子:
private void TextBlock_BookingsClick(object sender, MouseButtonEventArgs e)
{
try
{
(this.DataContext as PatientViewModel).ColumnName = (sender as TextBlock).Name.ToString();
(this.DataContext as PatientViewModel).PatientTabBookingsSorting();
}
catch (Exception ex)
{
PanLogger.Log(LogLevel.Error, String.Format("Bookings tab datagrid text block click event failed! \nReason: {0} \nStackTrace: {1} \nInnerException", ex.Message, ex.StackTrace, ex.InnerException));
}
}发布于 2014-08-25 14:22:58
尝试OriginalSource属性MouseButtonEventArgs --这将为您提供发生事件的确切控制
发布于 2014-08-25 14:18:50
我将得到发件人的类型,并检查这是否是一个文本框。
https://stackoverflow.com/questions/25487818
复制相似问题