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 492281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:05:47+00:00 2026-05-13T02:05:47+00:00

I’m very new to databinding, and so far have only had luck databinding to

  • 0

I’m very new to databinding, and so far have only had luck databinding to element properties in the GUI, or by binding to an ObservableCollection to display lists of data. Now I want to do something different.

I have a method that takes an index and returns a List of doubles, i.e.

List<double> GetValues( int index);

I have a GUI where the user selects the index from a combobox, and then several textboxes need to have their text updated with the values in the List. I actually have a thread running that caches all of this data, because I have UI elements in different places that consume and display the same information. So I figured, why not use databinding? The problem is, I have yet to find a good example online that explains how to take the index from the combobox, call the GetValues method, and then bind the resulting information to all of the textboxes — all from XAML.

The closest article I’ve found is http://msdn.microsoft.com/en-us/magazine/cc163299.aspx. Most of the articles I’ve read talk about using the Source attribute, but then say, “well, the easiest way is to just use StaticResource, so we’ll show you that method”.

How can this be accomplished? Would it be advisable to just go back to the easy way of doing this entirely from code-behind?

  • 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-13T02:05:47+00:00Added an answer on May 13, 2026 at 2:05 am

    The problem you’re having is that you’re trying to bind to the results from a function, and you may very well complicate things by trying to implement data-binding on something so simple from the code-behind. I’d recommend doing this from the code-behind.

    That said, for the simplest and most useful approach, you need to have actual properties in your class to bind to, which you need to update when the index changes. Depending on how you pass the data around, this could reduce the code-behind, or just create more.

    Here’s an example of what you could end up with:

    // Assume 1 of your textboxes displays a weight. Here's the property declaration:
    // Disclaimer: Not compiled or tested at all.
    public static readonly DependencyProperty WeightProperty = DependencyProperty.Register(
      "Weight", typeof(double), typeof(MyClass), new PropertyMetadata(0.0));
    
    public double Weight
    {
      get { return (double)this.GetValue(WeightProperty); }
      set { this.SetValue(WeightProperty); }
    }
    
    // Here's an example of setting the property:
    private void ComboBoxSelectedIndexChanged(object sender, RoutedEventArgs e)
    {
      List<double> values = myObject.GetValues(comboBox.SelectedIndex);
      this.Weight = values[0];
    }
    
    // And in your XAML, assuming you've given your Window the name myWindow:
    <TextBlock Text="{Binding ElementName=myWindow, Path=Weight}"/>
    

    This can be useful if you plan on updating the Weight property in multiple places and want the TextBlock to always show the correct value.

    On the other hand, if your properties will only update in the SelectedIndexChanged function and you don’t need the values outside of that function, you may as well have just set the value yourself and reduce the unnecessary overhead:

    private void ComboBoxSelectedIndexChanged(object sender, RoutedEventArgs e)
    {
      List<double> values = myObject.GetValues(comboBox.SelectedIndex);
      txtWeight.Text = values[0].ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.