开发者

problem in xbap mvvm implementation

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));
        }
  开发者_如何学Go  }        
}

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,


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}"/>


Based on your comment, to JSPrang's answer, I know whats wrong =)

XBAP is missing permissions to use reflection, and can therefore only bind to public classes, unless run in full trust.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜