views:

52

answers:

1

Hi,

I am trying to implement a mvvm design pattern for xbap application But unable to carry out simple text binding.

Following is the definition of my DemoViewModel.cs,

class DemoViewModel : INotifyPropertyChanged { string name;

    public event PropertyChangedEventHandler PropertyChanged;

    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
            OnPropertyChanged("Name");
        }
    }

    public DemoViewModel()
    {
        Name = "test";
    }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }        
}

I am binding the view to viewmodel using code behind of view,

public DemoView() { InitializeComponent(); DataContext = new DemoViewModel(); }

Following is the binding definition for text box present in view,

A: 

I appears that you have everything hooked up correctly. During execution, take a look at you 'Output' window and see if it gives you any warnings on you Binding. Also, try to simplify your xaml a bit to the following and see if this helps:

<TextBox Text="{Binding Name, Mode=TwoWay}"/>
JSprang
hey sorry for the delayed reply.... Things are working now as expected... but the only change i made is making DemoViewModel class as public..... But the same binding is working fine as wpf application with DemoViewModel class as private... can any reasons why the view model class should be made PUBLIC for xbap appl while itis not required in case of WPF?
Mstechuser1