MvvmLight 绑定

时间:2023-03-08 17:41:46
MvvmLight 绑定
  1. 添加MvvmLight引用,通过Nuget;
  2. 加载nuget以后会有ViewModelLocator.cs;
  3. 新建自己的ViewModel,继承ViewModelBase;
  4. View 通过资源引用Viewmodel :
    <UserControl.DataContext>
    <Binding Path="CommunicaitonPara" Source="{StaticResource Locator}"></Binding>
    </UserControl.DataContext>

    这是因为已经将ViewModelLocator设置为资源了。

  5. ViewModel写法  
     private string _ipAddress = "192.168.2.186";
    public string IpAddress
    {
    get { return _ipAddress; }
    set{Set(ref _ipAddress,value);}
    }
  6. 剩下就是正常的引用方式了

参考:

http://www.cnblogs.com/manupstairs/p/4890300.html 很详细。