【问题标题】:Silverlight data bind combobox items and value separatelySilverlight 数据分别绑定组合框项和值
【发布时间】:2011-03-25 09:52:40
【问题描述】:

我可以使用数据绑定将组合框的内容绑定到集合,或者我可以将组合框中的选定值绑定到类的成员,但我不能同时执行这两种操作。我希望能够将内容绑定到一件事并将选定的值绑定到另一件事,我猜组合框无法处理两个数据上下文,或者我没有明确指定它们。下面的示例,我将不胜感激!谢谢。

在 XAML 中:

<ComboBox Name="Combo" ItemsSource="{Binding}" 
          SelectedValue="{Binding ID, Mode=TwoWay}"/>

在代码中:

LayoutRoot.DataContext = myClass;
Combo.DataContext = items;

【问题讨论】:

    标签: silverlight data-binding


    【解决方案1】:

    这应该为你做,或者至少是接近的。

    <Grid DataContext="{Binding Source=MyObject}">
        <ComboBox x:Name="Combo"
                  ItemsSource="{Binding Source=MyCollection}"
                  SelectedValue="{Binding Path=ID, Mode=TwoWay}"/>
    </Grid>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      相关资源
      最近更新 更多