首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataGrid ColumnHeader PreviewLeftMouseButtonDown事件限制

DataGrid ColumnHeader PreviewLeftMouseButtonDown事件限制
EN

Stack Overflow用户
提问于 2014-08-25 14:09:20
回答 2查看 52关注 0票数 0

我有这样的数据栏标题:

代码语言:javascript
复制
<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>

现在它运行良好,唯一的问题是,当我单击文本框时,我希望限制事件触发。是否有方法检查是否已单击文本框并防止触发事件的功能?以下是我的事件在代码后面的样子:

代码语言:javascript
复制
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));
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-25 14:22:58

尝试OriginalSource属性MouseButtonEventArgs --这将为您提供发生事件的确切控制

票数 0
EN

Stack Overflow用户

发布于 2014-08-25 14:18:50

我将得到发件人的类型,并检查这是否是一个文本框。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25487818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档