我正在尝试将数据绑定到组合框。数据是来自数据库表的名称。从数据库中获取数据可以正常工作,因为我尝试将其绑定到列表视图,并且显示效果很好。我的问题是将其绑定到组合框,它什么也没显示。
谁能看到我出问题的地方了?
我的代码如下...
public string FullName
{
get
{
return String.Format("{0} {1}", _customer.ContactFirstName, _customer.ContactLastName);
}
}
XAML是
<ComboBox x:Name="comboBox" Grid.Row="1" Grid.ColumnSpan="2" Height="20" ItemsSource="{Binding Path=FullName}" >
下面是使用列表视图的XAML。
<ListView
AlternationCount="2"
DataContext="{StaticResource WorkorderGroups}"
ItemContainerStyle="{StaticResource WorkorderItemStyle}"
ItemsSource="{Binding}"
Grid.Row="2" Grid.ColumnSpan="3" Margin="1,0,-1,0>
<ListView.GroupStyle>
<StaticResourceExtension ResourceKey="WorkorderGroupStyle/>
</ListView.GroupStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=FullName}" />
</GridView>
</ListView.View>
</ListView>
您不能将字符串绑定到ComboBox。您需要将某些集合(如List<T>
或)绑定ObservableCollection<T>
到组合框ItemsSource。可能重复。请参阅链接。需要基于第二个ComboBox的SelectedValue设置WPF MVVM ComboBox ItemsSource的简单工作示例
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句