Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binding a custom property class WPF

Tags:

c#

binding

wpf

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

like image 985
jefsmi Avatar asked May 29 '26 14:05

jefsmi


1 Answers

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
            }
    }
 }
like image 191
Haris Hasan Avatar answered Jun 01 '26 02:06

Haris Hasan