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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:30:23+00:00 2026-05-20T15:30:23+00:00

I’ve been struggling to bind a TextBox.Text to some object’s public property but unfortunately

  • 0

I’ve been struggling to bind a TextBox.Text to some object’s public property but unfortunately I’m not quite there yet.

The actual XAML looks like:

<Window 
    <!-- skipped --> 
    xmlns:local="clr-namespace:Dotnet.Samples.Foobar"
    xmlns:system="clr-namespace:System;assembly=mscorlib">

    <Window.Resources>
        <local:Foobar x:Key="foobar" Foo="Lorem" Bar="Ipsum"
    </Window.Resources>
    <!-- skipped -->

        <TextBox Text="{Binding Source={StaticResource foobar}, Path=Foo}">
        <TextBox Text="{Binding Source={StaticResource foobar}, Path=Bar}">
        <!-- skipped -->
</Window>

With the data provider object being as simple as:

public class Foobar
{
    public string Foo { get; set; }
    public string Bar { get; set; }

    public Foobar()
    {

    }
}

I guess I’m sort of confused with WPF’s various binding options and I’m probably mixing them up so any advice will be definitely appreciated.

EDIT — All bindings are working ok, the remaining challenge is notifying changes from the Model to the ViewModel (the other way around works). I’ve committed the ‘broken’ code to an alternative repo:
http://nanotaboada.svn.beanstalkapp.com/dotnet/trunk/Dotnet.Samples.Rijndael/

Feel free to checkout and I’d be very happy to hear about any feedback about this. Thanks much in advance

  • 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-20T15:30:23+00:00Added an answer on May 20, 2026 at 3:30 pm

    The XAML binding engine isn’t finding an appropriate constructor to use, even though your constructor method parameters are optional. Therefore, you’ll either have to pass in the values for the constructor, or create a parameterless constructor which sets the value of Foo to a default value, or don’t use the ObjectDataProvider at all, and create an instance of your type directly as a resource.

    ...
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    ...
    
    <!-- Either create an instance of your type, and you can initialise the property values, this will require a default parameterless constructor -->
    <abc:Foobar x:Key="foobar2" Foo="Foo" />
    
    <!-- or pass the optional parameter values into your existing constructor -->
    <ObjectDataProvider x:Key="foobar" ObjectType="{x:Type abc:Foobar}">
      <ObjectDataProvider.ConstructorParameters>
        <system:String>Foo</system:String>
        <system:String>Bar</system:String>
      </ObjectDataProvider.ConstructorParameters>
    </ObjectDataProvider>
    

    Note that you’ll only need to implement INotifyPropertyChanged if your bindings are going to be invalidated in code, and you need to notify the UI. If you aren’t happy implementing this interface on your model types, then you can do this on your view models (assuming you’re using MVVM), but then you’ll need to find another mechanism to notify your view models when your model values change.

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

Sidebar

Related Questions

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
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.