Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7931717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:48:24+00:00 2026-06-03T20:48:24+00:00

I’m writing an MVVM WPF app with a datagrid of values which needs to

  • 0

I’m writing an MVVM WPF app with a datagrid of values which needs to be editable. The meaning of the value varies depending on other data, so I’ve written a usercontrol for editing them with a template that varies depending on the type of value. i.e. it may appear as a textbox, a combobox, or one of several other inhouse controls that link to databases to retrieve possible values.
This is the xaml I’ve used.

<DataGridTemplateColumn Header="Value">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <local:ValueViewingControl Value="{Binding Value}" ValueType="{Binding SettingValueType}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <local:ValueEditingControl Value="{Binding Value,Mode=TwoWay}" ValueType="{Binding SettingValueType}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

The problem is that once in editing mode, the next click on any part of the ValueEditingControl causes the cell to exit edit mode and go back to the ValueViewingControl before I can actually do anything.
I assume its something to do with the cell thinking its lost focus. Does anyone know a way of keeping the cell in edit mode until I actually tab or click out of the cell?

[edit]
A little more testing shows me that it works as expected if I use a textbox or a standard combobox as the edit control. This is making me think its the implementation of the custom controls I’ve written, which incorporate popups. When I select the popup that is part of the editing control, it thinks I’ve left the datagridcell and so ends editmode. How do I convince the datagridcell that the popup is inside it for focus purposes?
It must be possible or the combobox wouldnt work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:48:25+00:00Added an answer on June 3, 2026 at 8:48 pm

    Thanks to this question WPF Popup focus in data grid , I’ve figured out a partial solution to my own problem.
    The problem seems to be that the datagridcell over which my popups are floating is trying to snatch the focus when I click inside my popups.
    My solution is to add this handler and helper function to the usercontrol containing the popup

    Private Sub ControlRoot_PreviewLostKeyboardFocus(sender As System.Object, e As System.Windows.Input.KeyboardFocusChangedEventArgs)
        Dim popupelement As Popup = FindVisualChild(Of Popup)(ControlRoot)
        If (popupelement IsNot Nothing AndAlso popupelement.IsOpen) Then
            e.Handled = True
        End If
    End Sub
    
    Function FindVisualChild(Of T As DependencyObject)(ByVal element As DependencyObject) As T
        If element Is Nothing Then
            Return Nothing
        ElseIf TypeOf (element) Is T Then
            Return element
        Else
            Dim count = VisualTreeHelper.GetChildrenCount(element)
            For index As Integer = 0 To count - 1
                Dim child As DependencyObject = VisualTreeHelper.GetChild(element, index)
                If TypeOf (child) Is T Then
                    Return child
                Else
                    Dim grandchild As T = FindVisualChild(Of T)(child)
                    If grandchild IsNot Nothing Then Return grandchild
                End If
            Next
        End If
        Return Nothing
    End Function
    

    This stops the focus from leaving if the popup is open. It’s not perfect, so if anyone has a better solution I’m all ears, but it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.