我试图通过使用mvvm概念从数据库中获取输出。但是,输出不正确。值存储在变量中但不能绑定我可以做什么?
<StackPanel Margin="5"
DataContext="{Binding Path=LocationListModel, Mode=TwoWay}">
<Label Content="Location Name"/>
<ComboBox Name="cmbLocation"
Width="200"
ItemsSource="{Binding LocationList}"
DisplayMemberPath="LocationName"
SelectedItem="{Binding SelectedString}"/>
</StackPanel>
答案 0 :(得分:0)
我只是删除了XAML中的datacontext
**
<StackPanel Margin="5">
<Label Content="Location Name"/>
<ComboBox Name="cmbLocation"
Width="200"
ItemsSource="{Binding LocationList}"
DisplayMemberPath="LocationName"
SelectedItem="{Binding SelectedString}"/>
</StackPanel>
**
然后从c#代码中调用视图模型 喜欢
LocationListModel loc=new LocationViewModel();
//Constructer()
this.DataContext=loc;
//