【问题标题】:How to Bind with Combobox in silverlight如何在 silverlight 中与 Combobox 绑定
【发布时间】:2012-11-12 07:34:42
【问题描述】:

我想将我的国家集合绑定到一个组合框。

我的 XAML 页面如下所示:

<pmControls:pmComboBox 
    Margin="3" Grid.Row="5" Grid.Column="1"  
    ItemsSource="{Binding Path=Countries}" 
    SelectedValue="{Binding Title,Mode=TwoWay}" >
</pmControls:pmComboBox>

我想将 Title 显示为 DataTextField。

目前它在我的组合框列表中显示国家类的命名空间。 我也尝试添加 DisplayMemberPath,但它也不起作用。

如何设置组合框的显示字段以使用绑定?

【问题讨论】:

    标签: c# silverlight xaml


    【解决方案1】:

    我认为你需要这样做

    DisplayMemberPath="Title"
    SelectedValuePath="Title"
    SelectedValue="{Binding Path=Country,Mode=TwoWay}" 
    

    【讨论】:

    • 是的,它有效,我之前尝试过,但我给了 selectedValuePath="{Binding Title}"。我没有得到差异,请你解释一下。
    • 你没有指定SelectedValue="{Binding Path=Country,Mode=TwoWay}"
    • @Gayatri 当您设置的属性是“路径”时,您提供属性名称(即字符串),而不是绑定。
    猜你喜欢
    • 2012-03-27
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 2011-11-24
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多