数据绑定到组合框WPF XAML

时间:2015-02-13 16:38:10

标签: c# wpf xaml data-binding combobox

我试图将数据绑定到组合框。数据是来自数据库表的名称。从数据库获取数据工作正常,因为我试图将它绑定到列表视图,它显示正常。我的问题是将它绑定到一个组合框,它没有显示任何内容。

谁能看到我哪里出错了?

我的代码如下......

   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>

1 个答案:

答案 0 :(得分:1)

您无法将字符串绑定到ComboBox。您需要将诸如List<T>ObservableCollection<T>之类的集合绑定到组合框ItemsSource。可能重复。 请参阅链接。 Need SIMPLE working example of setting WPF MVVM ComboBox ItemsSource based on SelectedValue of second ComboBox

相关问题