English 中文(简体)
Wpf在电传Box出现时停止摩擦?
原标题:Wpf stop routing event when MessageBox appear?

I ve PreviewMouseDown event on TreeView in order to determine if user can select other item based on some logic. If the current item data changed, will appear MessageBox that asks the user if he want to discard the changes. if user press YES , I set e.Handled = false; to enable the new selection. and if user press NO, I set e.Handled = true; to cancel the new selection.

问题是,尽管我制定了<代码>e.Handled = 虚假,但该活动停止,在树冠上没有发生选择活动。 有些人已经找到了解决办法?

提前感谢!

最佳回答

对电文箱的重心改动取消了 mo倒性活动,因此无论处理是否处理,都无关紧要。 既然你知道用户试图在你展示电文之前选择哪项物品,那么如果用户使用YES的话,就简单地从方案角度选择该项目。

问题回答

我认识到这是一个老问题,我还要补充我的回答。

实际上,@yos Commonl, 您的指定官员知道用户试图从MouseEventArgs中挑选哪项物品。 你们需要看一下,例如,原件Source(可能是文本Block),这是用户点击的。 因此,它有数据内容。

因此,将“树木”定在“原始数据”上。

In VB, you can be explicit or implicit: myTreeView.SelectedItem = CType(e.OriginalSource, TextBlock).DataContext() myTreeView.SelectedItem = e.OriginalSource.DataContext()

In C#, you will need to determine the type of e.OriginalSource. Do this by putting in a break point, and see what Studio tells you that it is. In this example: myTreeView.SelectedItem = ((TextBlock)e.OriginalSource).DataContext()

这是我自己的法典的一个例子。 在我的案件中,它用的是数据Grid,而不是一 Tree树,但应当做同样的工作。 如果在选定项目上出现无动于衷的变化,我就利用该守则促使用户。 如果用户对“无储蓄的继续使用”的回答是“什么”的话,则该守则继续采用新的选择。 否则,我就请电文箱阻挡“通道”,阻止“选择”活动发射。

    Private Sub dgDataGrid_PreviewMouseLeftButtonDown(sender As Object, e As System.Windows.Input.MouseButtonEventArgs) Handles dgDataGrid.PreviewMouseLeftButtonDown
    If dgDataGrid.SelectedItem IsNot Nothing Then
        If MyDataContext.ExternalViewModel.ItemIsModified Then
            Dim prompt As String = String.Format("Changes have not been saved.{0}{0}Continue without saving?", vbCrLf)
            Dim title As String = "Changes Not Saved"
            Dim result As MsgBoxResult = MsgBox(prompt, MsgBoxStyle.Exclamation Or MsgBoxStyle.YesNo, title)
            If result = MsgBoxResult.Yes Then
                dgDataGrid.SelectedItem = e.OriginalSource.DataContext()
            End If
        End If
    End If
End Sub

Private Sub dgDataGrid_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles dgDataGrid.SelectionChanged
    MyDataContext.SetSearchItem(dgDataGrid.SelectedItem)
End Sub




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签