i'm trying to bind a simple textbox to a message string returned from object.
first i have a base class -
public class BaseClass : INotifyPropertyChanged
{
private string message
public string Message
{ get {return message;}
set
{ message = value;
OnPropertyChaned("Message");
}
}
public event PropertyChangedEventHandler propertyChanged;
private void OnPropertyChanged(string propertyName)
{
if(propertyChanged!=null)
propertyChanged(this, new PropertyChanedEventArgs(propertyName));
}
}
Also, i have a sub-class -
public Class SubClass : BaseClass
{
}
my viewModel class -
public class ViewModel
{
private BaseClass theClass;
public ViewModel()
{
base=new BaseClass();
}
public BaseClass TheClass
{
get{ return theClass;}
set{ theClass= value;}
}
private void someBtnClickMethod()
{
TheClass = new SubClass();
theClass.Message="123";
}
}
i'm binding the textBox with -
the problem is that when someBtnClickMethod function call than i have to change the object and then binding not working for me, message is not updated in textBox.
what's the problem? how can i fix that?
thanks in advanced.
bobbyPosted Dec 27, 2014, 3:32 AM
i guess i will need to use a different view for each sub-class
swapnil silamPosted Dec 24, 2014, 2:22 AM
Firstly you make sure that you have added datacontext into you xaml code and then specify binding mode="TwoWay" or "OneWay" for textbox.
Add datacontext like this
xmlns:vm="clr-namespace:
Now you set textbox binding mode
May this answer may help you.