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 ;)

jefsmi
  • 721
  • 2
  • 9
  • 19
  • 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? – Andreas H. Oct 25 '11 at 12:10
  • Did you set the windows datacontext binding correct? – jrb Oct 25 '11 at 12:13
  • Does your ViewModel implement INotifyPropertyChanged, i see you are calling the base.RaisePropertyChanged. – BigL Oct 25 '11 at 12:16
  • I implemented the INotifyPropertyChanged and the windows datacontext is bound correctly. And for Andreas can you restate your question pls? – jefsmi Oct 25 '11 at 12:19
  • So if you put a textbox outside the grid it bind's correct? And just a quick check.. uses RFP while your prop is named Rfp – jrb Oct 25 '11 at 12:26
  • Tried to set it outside the grid and that doens't changes mutch, same for the second suggestion. Quick comment my textbox is located in a tabitem wich I made in a different userControl I bound it due a dataTemplate. – jefsmi Oct 25 '11 at 12:36
  • Only thing i can think of is that your windows datacontext isn't inherited correct. Check this link and try it. http://stackoverflow.com/questions/1658397/wpf-datagrid-header-text-binding – jrb Oct 25 '11 at 12:41
  • @jrb the datacontext is set on the Grid so the items in the grid will inherit it and he could use it correctly i guess the problem will be somewhere with the INotifyPropertyChanged interface maybe you should implement it on your class too the way Vijay suggests. – BigL Oct 25 '11 at 13:06
  • My datacontext is indeed bound correctly cause I show a list in my screen which is bound in the ViewModel. It's just the custom made prop class which isn't doing it's work. I tried to implement the INotifyPropertyChanged in the class itself but that doesn't made any diff. – jefsmi Oct 25 '11 at 13:19
  • As a diagnostic step, try setting the `Text` property to `"{Binding}"` - this will display the type name of the current `DataContext` in the `TextBox` and should allow you to work out what binding path you need – Steve Greatrex Oct 25 '11 at 14:49

3 Answers3

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
            }
    }
 }
Haris Hasan
  • 29,856
  • 10
  • 92
  • 122
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.

S2S2
  • 8,322
  • 5
  • 37
  • 65
0

You forget to add inheritance from INotifyPropertyChanged