3

I got a custom WPF property class named "RFPGegevens"

public class RFPGegevens
{
    private string _klant;
    public String Klant
    {
        get { return _klant; }
        set { _klant = value; }
    }
 }

In my ViewModel I got a property RFPGegevens

    private RFPGegevens _rfpGegevens;

    public RFPGegevens RfpGegevens
    {
        get
        {
            if (_rfpGegevens == null)
                _rfpGegevens = new RFPGegevens();
            return _rfpGegevens;
        }
        set
        {
            _rfpGegevens = value;
            base.RaisePropertyChangedEvent("RfpGegevens");
        }
    }

This property is filled correctly, if I debug this is the result:

enter image description here

In my View I'm binding the property "RFPGegevens" to the datacontext of my Grid

<Grid DataContext="{Binding RfpGegevens}">

and still if I debug the "Klant" property field is filled.

enter image description here

But as I bind this property in the View my textbox is still empty.

<TextBox Text="{Binding Klant, Mode=TwoWay}"/>

I also tried this but nothings seems to work:

<TextBox Text="{Binding RFPGegevens.Klant, Mode=TwoWay}"/>

Don't know what I'm doing wrong.
Thanks in advance ;)

10
  • Where did you debug the get-accessor? Is it ensured, that it is called by the WPF, for the TextBox-Binding? What does the output-window in VS say about the binding, when running? Commented Oct 25, 2011 at 12:10
  • Did you set the windows datacontext binding correct? Commented Oct 25, 2011 at 12:13
  • Does your ViewModel implement INotifyPropertyChanged, i see you are calling the base.RaisePropertyChanged. Commented Oct 25, 2011 at 12:16
  • I implemented the INotifyPropertyChanged and the windows datacontext is bound correctly. And for Andreas can you restate your question pls? Commented Oct 25, 2011 at 12:19
  • So if you put a textbox outside the grid it bind's correct? And just a quick check.. <TextBox Text="{Binding RFPGegevens.Klant, Mode=TwoWay}"/> uses RFP while your prop is named Rfp Commented Oct 25, 2011 at 12:26

3 Answers 3

1

try with two things

<TextBox Text="{Binding Klant, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

public class RFPGegevens
{
    private string _klant;
    public String Klant
    {
        get { return _klant; }
        set {
              _klant = value; 
              //Raise the property changed event here
            }
    }
 }
Sign up to request clarification or add additional context in comments.

Comments

1

You need to implement the INotifyPropertyChanged interface for your custom class also as below:

public class RFPGegevens : INotifyPropertyChanged

and raise the propertychanged events from the set accessor of your properties.

Comments

0

You forget to add inheritance from INotifyPropertyChanged

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.