ObjectDataProvider未找到wpf本地类型

时间:2013-07-26 14:54:02

标签: c# wpf xaml data-binding wpfdatagrid

我看过了,但我找不到这个错误的答案(我明白了!)。

我在这里处理这篇文章CodeProject Datagrid practical example 并尝试修改我在WPF中的简单CRUD屏幕的代码,我是新手

我相信我正在尝试将对象实例化并用作数据网格的数据源 但是在构建时我得到了以下错误,我显然不明白。

我认为我的xaml键中的objectdataprovider是CustomerScheduleDataProvider的类,类型是构造函数,但显然不是,如果示例标记是 CustomerDataProvider 部分代码是我已经取代了我的班级名称

有人可以指出我错过了什么,非常感谢 伊恩

  

                                                  

     

找不到类型'local:CustomerScheduleDataProvider'。      在MS.Internal.Platform.MemberDocumentValueSerializer`1.ConvertToDocumentValue(ITypeMetadata类型,字符串值,IServiceProvider documentServices)      在MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlMarkupExtensionPropertyBase.get_Value()      在MS.Internal.Design.DocumentModel.DocumentTrees.DocumentPropertyWrapper.get_Value()      在MS.Internal.Design.DocumentModel.DocumentTrees.InMemory.InMemoryDocumentProperty..ctor(DocumentProperty属性,InMemoryDocumentItem项目)      在MS.Internal.Design.DocumentModel.DocumentTrees.InMemory.InMemoryDocumentItem.SetUpItem(DocumentItem item)

这是我的标记和代码我已经包含了我的参考文献,因为我的经验是有经验的程序员错过了这些,我们新手没有意识到我们应该使用哪些!

<Window 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Customer Forecast Input" Height="300" Width="600">

<Window.Resources>
    <!-- create an instance of our DataProvider class -->
    <ObjectDataProvider x:Key="CustomerScheduleDataProvider"
        ObjectType="{x:Type local:CustomerScheduleDataProvider}"/>

    <!-- define the method which is invoked to obtain our data -->
    <ObjectDataProvider x:Key="CustomerSchedule"
      ObjectInstance="{StaticResource CustomerScheduleDataProvider}"
      MethodName="GetCustomerSchedules"/>
</Window.Resources>

<DockPanel DataContext="{Binding Source={StaticResource CustomerSchedule}}">
    <dg:DataGrid ItemsSource="{Binding}" Name="dataGrid"/>
</DockPanel>
</Window>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CustomerForecastInput
{
   public class CustomerScheduleDataProvider
   {
   private SysproCompanyTDataSetTableAdapters.CustomerSchedulesTableAdapter CSadapter;
   private SysproCompanyTDataSet ds;

   public CustomerScheduleDataProvider()
   {
       ds = new SysproCompanyTDataSet();
       CSadapter = new SysproCompanyTDataSetTableAdapters.CustomerSchedulesTableAdapter();
       CSadapter.Fill(ds.CustomerSchedules);
    }
   public DataView GetCustomerSchedules()
   {
       return ds.CustomerSchedules.DefaultView;

   }
 }
}

1 个答案:

答案 0 :(得分:2)

在使用之前,您没有在XAML中声明命名空间。因此,请在Window标记中添加以下声明。

xmlns:local="clr-namespace:CustomerForecastInput"