【问题标题】:Combobox item source does not work in silverlight datagrid组合框项目源在 silverlight 数据网格中不起作用
【发布时间】:2012-05-02 15:49:23
【问题描述】:

我想为 silverlight 数据网格中的组合框绑定 ItemSource。 它不显示绑定值。我有一个来自的动态 ItemSource 值 数据库。我该怎么做?

【问题讨论】:

  • public ObservableCollection AndOrs { get { return _andor; } 设置 { _andor = 值; RaisePropertyChanged("AndOrs"); } }

标签: silverlight


【解决方案1】:

目前您的组合框可以t find the value coz it trying to find it in items(DataGrid 绑定到)名为“AndOrs”的字段。如果您想将列绑定到整体上独立于 DataGrid,您应该使用完整路径/rel。在 DataContext 中搜索所需属性并绑定到它的源。例如,如果用于 DataGrid 的 ItemsSource 的集合在 AndOrs 附近定义:

<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=sdk:DataGrid}, Path=DataContext.AndOrs}"/>

附: 我猜 AndOrs 属性未在您用于 DataGrid 绑定到的项目中定义。

【讨论】:

  • AncestorType 在 SL5 中是新的,但由于我正在使用组件,我必须使用不支持 AncestorType 的 SL4。是否有任何命令代替 AncestorType?
  • SL4 中没有“AncestorType”等价物
  • 在 SL4 中你有什么替代方法吗?
【解决方案2】:

我也有同样的问题。对于 SL4,我能找到的最好方法是使用静态资源。

请看这里:http://blog.digitaltools.com/post/2011/05/06/Binding-a-Datagride28099s-ComboBox.aspx

或者,通过在 xaml 中创建静态资源:http://forums.silverlight.net/post/370135.aspx

【讨论】:

    猜你喜欢
    • 2012-01-28
    • 1970-01-01
    • 2022-01-07
    • 2020-12-13
    • 1970-01-01
    • 2011-02-25
    • 2012-10-15
    • 2012-05-15
    • 1970-01-01
    相关资源
    最近更新 更多