tags:

views:

252

answers:

2

Hi

I have a textbox in XAML file, On Changing the text in the textbox the prop setter is not getting called. I am able to get the value in ProjectOfficer textbox and not able to update it. I am using MVVM pattern

Below is my code XAML

 TextBox Text="{Binding Path=Officer,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                                x:Name="ProjectOfficer"/>

ViewModel.cs

    public Staff Officer 
    { 
        get 
        { 
            return __con.PrimaryOfficer  ; 
        } 
        set 
        { 
            _con.PrimaryOfficer = value; 
           _con.PrimaryOfficer.Update(true); 
         } 
    }

Staff.cs

public class Staff : EntityBase 
{ 
    public Staff();

    public string Address { get; } 
    public string Code { get; set; } 
    public override void Update(); 
}

Thanks

+3  A: 

You're binding a property of type string on the TextBox to a property of type Officer on your ViewModel. I expect the setter isn't being called because WPF can't do the conversion.

If you check the output window in visual studio, you'll probably see a binding error for this property.

Samuel Jack
+1  A: 

Try something like:

TextBox text ="{Binding Path=Address,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                            x:Name="ProjectOfficer"/>

Make sure the holder of the TextBox is linked to a Staff object. The textbox cannot bind directly to an object without telling the property to display (like Address in my example above).

Daok
I'd modify this, but I don't have the rep... I think "txtAddress" should be "Text" here.
Anderson Imes