【问题标题】:ObjectDataProvider wpf local type not found找不到 ObjectDataProvider wpf 本地类型
【发布时间】:2013-07-26 14:54:02
【问题描述】:

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

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

我相信我正在尝试将一个对象实例化并用作数据网格的数据源 但在我对构建的标记中,我收到以下错误,我显然不明白。

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

谁能指出我错过了什么,非常感谢 伊恩

找不到类型“本地:CustomerScheduleDataProvider”。 在 MS.Internal.Platform.MemberDocumentValueSerializer`1.ConvertToDocumentValue(ITypeMetadata 类型,字符串值,IServiceProvider 文档服务) 在 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 项)

这是我的标记和代码,我已经包含了我的参考资料,因为我的经验是经验丰富的编码人员错过了这些,而我们这些新手不知道我们应该使用哪些!

<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;

   }
 }
}

【问题讨论】:

    标签: c# wpf xaml data-binding wpfdatagrid


    【解决方案1】:

    在使用之前,您没有在 XAML 中声明命名空间。所以把下面的声明放在你的 Window 标签中。

    xmlns:local="clr-namespace:CustomerForecastInput"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多