Search code examples
c#wpfxamldata-bindingwpfdatagrid

ObjectDataProvider wpf local type not found


I have had a look but I can not find the answer to this error (That I understand!).

I am working through this article here CodeProject Datagrid practical example and trying to modify the code for my simple CRUD screen in WPF, which I am new to

I believe I am trying to get an object instantiated and used as the datasource to the data grid but in my mark up on build I get the following error, which I clearly do not understand.

I thought that the objectdataprovider in my xaml key was the class of the CustomerScheduleDataProvider and the type is the constructor, but clearly not, if the example markup it is the CustomerDataProvider part of the code is where I have substituted my class name

Can someone please point out what I am missing, many Thanks Ian

Type 'local:CustomerScheduleDataProvider' was not found. at MS.Internal.Platform.MemberDocumentValueSerializer`1.ConvertToDocumentValue(ITypeMetadata type, String value, IServiceProvider documentServices) at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlMarkupExtensionPropertyBase.get_Value() at MS.Internal.Design.DocumentModel.DocumentTrees.DocumentPropertyWrapper.get_Value() at MS.Internal.Design.DocumentModel.DocumentTrees.InMemory.InMemoryDocumentProperty..ctor(DocumentProperty property, InMemoryDocumentItem item) at MS.Internal.Design.DocumentModel.DocumentTrees.InMemory.InMemoryDocumentItem.SetUpItem(DocumentItem item)

Here is my mark up and code I have included my references because my experience is these are missed out by the experienced coders and us newbies do not realise which ones we should be using!

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

   }
 }
}

Solution

  • You did not declare the namespace in XAML before using it. So put below declaration in your Window tag.

    xmlns:local="clr-namespace:CustomerForecastInput"