What do I need to further qualify the DataContext for a binding?

前端 未结 2 904
你的背包
你的背包 2020-12-15 17:46

The files I have created and will be referring to in this question are:

TechnicainSelectionView.xaml
TechnicianSelectionView.cs
TechnicianSelectionViewModel.         


        
相关标签:
2条回答
  • 2020-12-15 18:25

    You need to specify the type of data context in the xaml to get design-time support. Even though you assigned the data context in code-behind, the designer is not going to recognize that.

    Try putting the following in your xaml:

    d:DataContext="{d:DesignInstance vm:TechnicianSelectionViewModel}"
    

    See this link for more details.

    0 讨论(0)
  • 2020-12-15 18:45

    In my Xamarin Forms Xaml file I used the following lines in the header (ContentPage tag) and it worked perfectly as I wanted.

    Basically now

    • the intellisense shows the fields in the binding
    • my Resharper is able to rename the binding in the Xaml file if I refactor the name of the property

      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:vm="clr-namespace:YourApplicationName.ViewModels;assembly=YourApplicationName"
      mc:Ignorable="d"
      d:DataContext="{d:DesignInstance {x:Type vm:CurrentPageViewModel}}"
      
    0 讨论(0)
提交回复
热议问题