Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! Im trying read my settingsfile which is deserialized into class and bind its propertys and show it in my UI.

Here is simple demostration what im doing.
My testClass
public class TestClass
{
    private string property;

    public string Property
    {
        get { return property;  }
        set { property = value; }
    }
}

In my application I have created TestClass and I insert some string into my property. Then I do following bindings to my UI component
//lets bind data     
Binding binding = new Binding("Property");
binding.Mode    = BindingMode.TwoWay;
binding.Source  = testClass.Property;
//Bind to Ui control
this.txtBox.SetBinding(TextBox.TextProperty,binding);

When I run my application nothing happens in my textbox. I havent made InotifypropertyChange events in this demostration because im reading static data (settings file) in my real problem.

Hope you got my idea!

Cheers :)
Posted
Updated 16-Dec-10 2:22am
v2

1 solution

Change the following to

C#
//lets bind data     
Binding binding = new Binding("Property");
binding.Mode    = BindingMode.TwoWay;
binding.Source  = testClass;
//Bind to Ui control
this.txtBox.SetBinding(TextBox.TextProperty,binding);


or

C#
//lets bind data     
Binding binding = new Binding();
binding.Mode    = BindingMode.TwoWay;
binding.Source  = testClass.Property;
//Bind to Ui control
this.txtBox.SetBinding(TextBox.TextProperty,binding);


When you specify Path on the Binding class contructor, the Source property should be the object.
 
Share this answer
 
Comments
paleGegg0 17-Dec-10 0:25am    
Thank you so much! I have been blind, I have been searching answer and saw examples, but always coded source property to property instead of object. I really need vacation :)
Venkatesh Mookkan 17-Dec-10 1:08am    
You are welcome. And thank you for marking it as Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900