【问题标题】:Databinding to combo box WPF XAML数据绑定到组合框 WPF XAML
【发布时间】:2015-02-14 01:14:33
【问题描述】:

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

谁能看到我哪里出错了?

我的代码如下...

   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>

【问题讨论】:

  • 请发布更多代码...

标签: c# wpf xaml data-binding combobox


【解决方案1】:

您不能将字符串绑定到 ComboBox。您需要将一些集合(如List&lt;T&gt;ObservableCollection&lt;T&gt;)绑定到组合框ItemsSource。可能重复。 参考链接。 Need SIMPLE working example of setting WPF MVVM ComboBox ItemsSource based on SelectedValue of second ComboBox

【讨论】:

  • 我在想 .. 他的 ListView 是如何工作的 .. 与列表视图不一样吗?
  • @user3244139 是FullName List&lt;string&gt; 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-17
  • 1970-01-01
  • 2022-10-07
  • 1970-01-01
  • 1970-01-01
  • 2015-09-15
  • 2015-12-12
相关资源
最近更新 更多