Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Show Dialog from 'PreviewMouseLeftButtonDown' event handler in 'DataGridCell' does not recognize first touch.

$
0
0

Hi,

I have to display a pop-up custom keyboard when user touches on a datagrid cell. It works fine when I click on it using mouse but when i use Touch, first touch is neglected. I checked at touch preview event on the target window it is triggered but it does not raise btn1.Click or similar touch events. On a second touch everything starts to work.

This same window when poped-up from a user control works fine without any issues. Touch is accepted on first touch.

Window is displayed as ShowDialog from a 'PreviewMouseLeftButtonDown' event handler in 'DataGridCell'. It almost looks like some bug by WPF. Please look at code below and let me know if you find anything. I already tried window.focus and window.activate and none helped.

I have the following code for event handler in XAML.

<DataGridTextColumn x:Name="SPCol" Binding="{Binding Path=LpSPs,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="*" IsReadOnly="False" ElementStyle="{StaticResource HollCenterAlignStyle}"><DataGridTextColumn.CellStyle><Style TargetType="DataGridCell"><EventSetter Event="PreviewMouseLeftButtonDown" Handler="EnterSP"/></Style></DataGridTextColumn.CellStyle></DataGridTextColumn>

Here is the event handler

Private Sub EnterSP(sender As Object, e As MouseButtonEventArgs)
         Try
             Dim row As DataGridRow
             Dim dep As DependencyObject = CType(e.OriginalSource, DependencyObject)
             While dep IsNot Nothing And Not TypeOf dep Is DataGridCell And Not TypeOf dep Is Primitives.DataGridColumnHeader
                 dep = VisualTreeHelper.GetParent(dep)
             End While
             Dim cell As DataGridCell = sender
             If (cell IsNot Nothing And Not cell.IsEditing) Then
                 ' If (Not cell.IsFocused) Then
                 cell.Background = FindResource("mBlue")
                 cell.BorderBrush = FindResource("mBlue")
                 cell.Content.Foreground = FindResource("mWhite")
                 'End If
                Dim col As DataGridBoundColumn = cell.Column
                 ' find the property that this column is bound to
                 Dim binding As Binding = col.Binding
                 Dim boundPropertyName As String = binding.Path.Path
                 row = Nothing
                 If TypeOf dep Is DataGridCell Then
                     Dim cell1 As DataGridCell = DirectCast(dep, DataGridCell)
                     ' navigate further up the tree
                     While dep IsNot Nothing And Not TypeOf dep Is DataGridRow
                         dep = VisualTreeHelper.GetParent(dep)
                     End While

                    row = DirectCast(dep, DataGridRow)
                 End If
                 cell.IsEditing = False
                 'get row index
                 Dim dataGrid As DataGrid = DirectCast(ItemsControl.ItemsControlFromItemContainer(row), DataGrid)
                 Dim index As Integer = dataGrid.ItemContainerGenerator.IndexFromContainer(row)
                 Dim data As Object = row.Item
                 Dim LpNum = CType(data, LoopParameters).LpId
                 If (SingleView = True) Then
                     If (BF315Unit.Loops(LpNum).LoopType <> clsBF315Loop.LpType.LT_NONE) Then
                         Dim ne = New WinNum(sender)
                         ne.SetExistingValue("Setpoint", BF315Unit.Loops(LpNum).SetPoint)
                         ne.SetLimits(CDbl(BF315Unit.Loops(LpNum).SPLowLimit), CDbl(BF315Unit.Loops(LpNum).SPHighLimit))
                         ne.Topmost = True
                         If (ne.ShowDialog()) Then
                             Dim val As Single = ne.ReturnValue
                             BF315Unit.ChangeSetpoint(LpNum, val)
                         End If
                     End If
                 End If
                 cell.Background = FindResource("mWhite")
                 cell.BorderBrush = FindResource("mWhite")
                 cell.Content.Foreground = FindResource("mAnthrazit")
             End If
         Catch ex As Exception
             MsgBox(ex.ToString)
         End Try
     End Sub



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>