我看过但我找不到这个错误的答案(我明白了!)。
我正在阅读这篇文章CodeProject Datagrid 实际示例 ,并尝试在 WPF 中修改我的简单 CRUD 屏幕的代码,我是新手
我相信我正在尝试将一个对象实例化并用作数据网格的数据源,但是在构建标记时出现以下错误,我显然不明白。
我认为我的 xaml 键中的 objectdataprovider 是 CustomerScheduleDataProvider 的类,类型是构造函数,但显然不是,如果示例标记是代码的CustomerDataProvider部分,我已经替换了我的类名
有人可以指出我错过了什么,非常感谢伊恩
找不到类型“本地:CustomerScheduleDataProvider”。在 MS.Internal.Platform.MemberDocumentValueSerializer`1.ConvertToDocumentValue(ITypeMetadata type, String value, 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 项)
这是我的标记和代码,我已经包含了我的参考资料,因为我的经验是经验丰富的编码人员错过了这些,我们新手不知道我们应该使用哪些!
<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;
}
}
}