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

  • SEARCH
  • Home
  • 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 6698541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:35:24+00:00 2026-05-26T06:35:24+00:00

Need a TextBox in a ListView DataTemplate to call set on either LostFocus or

  • 0

Need a TextBox in a ListView DataTemplate to call set on either LostFocus or enter key. Used UpdateSourceTrigger = Explicit and events for LostFocus and KeyUp. Problem is that I cannot get a valid reference to the BindingExpression.

XAML

    <ListView x:Name="lvMVitems" ItemsSource="{Binding Path=DF.DocFieldStringMVitemValues, Mode=OneWay}">
        <ListView.View>    
            <GridView>
                <GridViewColumn x:Name="gvcExistingValue">
                    <GridViewColumnHeader Content="Value"/>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox x:Name="tbExistingValue"
                                Text="{Binding Path=FieldItemValue, Mode=TwoWay, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=Explicit}"
                                Validation.Error="Validataion_Error" 
                                LostFocus="tbExistingValue_LostFocus" KeyUp="tbExistingValue_KeyUp" />                                   
                        </DataTemplate>                                  
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

Code Behind NOT working

    private void tbExistingValue_LostFocus(object sender, RoutedEventArgs e)
    {
        BindingExpression be = lvMVitems.GetBindingExpression(ListView.SelectedItemProperty);
        be.UpdateSource();
    } 

be is null. I have tried ListView.SelectedValueProperty and ListView.SelectedPathProperty. If it try tbExistingValue it fails with a message “does not exists” and will not even compile. How do I get the proper BindingExpression?? Thanks.

If I set UpdateSourceTrigger = LostFocus and remove the event handlers it does call set properly. There is a valid twoway binding there. I just cannot get a valid reference to BindingExpression (be) using explicit.

It works fine for a TextBox directly on page (in a grid cell). The xaml below works:

    <TextBox Grid.Row="1" Grid.Column="1" x:Name="strAddRow" 
             Text="{Binding Path=DF.NewFieldValue, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=Explicit}"
             Validation.Error="Validataion_Error" 
             LostFocus="strAddRow_LostFocus" KeyUp="strAddRow_KeyUp"/>

This BindingExpression works fine:

    private void strAddRow_LostFocus(object sender, RoutedEventArgs e)
    {
        BindingExpression be = strAddRow.GetBindingExpression(TextBox.TextProperty);
        be.UpdateSource();
    }
  • 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-05-26T06:35:25+00:00Added an answer on May 26, 2026 at 6:35 am

    Since you apply the binding on your Textbox’s Text DP, so you need to fetch the binding from there only like this –

    private void tbExistingValue_LostFocus(object sender, RoutedEventArgs e)
    {
       BindingExpression be = (sender as TextBox).GetBindingExpression(TextBox.TextProperty);
       be.UpdateSource();
    }
    

    Moreover, you haven’t bind the ListView SelectedItem with any property of your ViewModel. To retrieve the binding, it should be atleast binded to some value. So, you should bind it to your FieldValueProperty then you won’t get null value with your code in place.

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

Sidebar

Related Questions

I need to set the height of every textbox on my form, some of
I need to be able to get and set the textbox's text, but I
'> ı need textbox text set DateTime.Now.ToLongDateString() how to make ? must inline
i need a textbox with a bottom-line such like inputfields used in forms. I
I need to get textbox that exits in Formview inserttemplate via javascript. Both return
I need to dynamically create textbox. This is my code, but with this I
I need to copy a text from a textbox into the clipboard with ASP.NET.
I need to get a value from a textbox inside a FooterTemplate in the
I need some help with a textbox: The textbox is only allowed to contain
I need to know the maximum length of a textbox in ssrs. How much

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.