将Silverlight 4中的绑定绑定到DataGridColumn中的ComboBox

时间:2011-07-14 19:12:54

标签: c# silverlight wcf-binding

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

我在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完成之前绑定到列表。有没有这样做的解决方案,还是我应该放弃并尝试别的东西?

由于

1 个答案:

答案 0 :(得分:0)

尝试在CategoriesProvider上实现INotifyPropertyChanged。 CategoriesList在哪里?这就是你应该通知的内容发生了变化。

相关问题