Accessing Properties in other ViewModels in MVVM Light

前端 未结 3 1152
说谎
说谎 2020-12-14 12:51

I have a main ViewModel containing a List of items which I\'m using in a certain amount of UserControls, which are displayed in a ContentCont

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 13:38

    If all you need is to bind a property from the main viewmodel, while inside the content control, just use this syntax:

       ... Binding="{DataContext.mainvmpropertyname, ElementName=xxxx}"
    

    where xxxx is the Name attached to the content control (or any control that has the main viewmodel as its DataContext). Alternatively, you can use relative binding instead of element name.

提交回复
热议问题