【问题标题】:Binding in Silverlight 4 to ComboBox in DataGridColumn在 Silverlight 4 中绑定到 DataGridColumn 中的 ComboBox
【发布时间】:2011-10-05 15:15:27
【问题描述】:

您好,我一直在到处寻找解决此问题的方法,但找不到解决方案。

我在 datagrid 列中有一个组合框,我想将它的 itemsource 绑定到由数据库生成的列表。 我还想将选定的值绑定到单独的表。 我已经成功地做到了……但只是有时。有东西不同步。 这是一些代码

xaml:

<Grid.Resources>
    <my:CategoriesProvider x:Key="categoriesProvider"/>
</Grid.Resources>

..................................

    <data:DataGridTemplateColumn Header="Category" Width="100" x:Name="cboDataCol">
                          <data:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate x:Name="cboDataTemplate">
   <ComboBox Name="cboCategories" SelectedItem="{Binding category, Mode=TwoWay}" ItemsSource="{Binding CategoriesList,Source={StaticResource categoriesProvider}}" DisplayMemberPath="name" SelectedValue="{Binding Path=category.id}"  SelectedValuePath="id"/>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellEditingTemplate>
                    </data:DataGridTemplateColumn>

C#:

public class CategoriesProvider : List<category>
    {
        MenuItems.MenuItemService.MenuItemServiceClient svc = new     MenuItems.MenuItemService.MenuItemServiceClient();
        ObservableCollection<category> allCategories;

        public CategoriesProvider()
        {
            svc.getCategoriesCompleted += new EventHandler<getCategoriesCompletedEventArgs>(svc_getCategoriesCompleted);

            svc.getCategoriesAsync();
        }

        public void svc_getCategoriesCompleted(object sender, getCategoriesCompletedEventArgs e)
        {
            //m_autoresetevent.Set();
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                allCategories = e.Result;
                if (allCategories == null)
                {
                    MessageBox.Show("NULL123");
                }
            });


        }

有时控件似乎在 getItemsAsync 完成之前绑定到列表。有没有办法解决这个问题,还是我应该放弃并尝试其他方法?

谢谢

【问题讨论】:

    标签: c# silverlight wcf-binding


    【解决方案1】:

    尝试在您的 CategoriesProvider 上实现 INotifyPropertyChanged。类别列表在哪里?这就是您应该通知更改的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 2011-02-17
      • 2012-03-10
      • 2011-05-29
      相关资源
      最近更新 更多