我已经查看过,但找不到此错误的答案(我明白!)。
我正在这里阅读这篇文章CodeProject Datagrid practical example 并尝试修改 WPF 中我的简单 CRUD 屏幕的代码,这是我刚接触的
我相信我正在尝试实例化一个对象并将其用作数据网格的数据源 但在我的构建标记中,我收到以下错误,我显然不明白。
我认为我的 xaml 键中的 objectdataprovider 是 CustomerScheduleDataProvider 的类,类型是构造函数,但显然不是,如果示例标记是代码的 CustomerDataProvider 部分,我已经替换了我的类(class)名称
有人可以指出我缺少什么吗,非常感谢 伊恩
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)
这是我的标记和代码,我已经包含了我的引用资料,因为我的经验是经验丰富的编码人员会错过这些,而我们新手不知道我们应该使用哪些!
<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;
}
}
}
最佳答案
您在使用命名空间之前没有在 XAML 中声明它。因此,请将以下声明放入您的 Window 标记中。
xmlns:local="clr-namespace:CustomerForecastInput"
关于c# - 未找到 ObjectDataProvider wpf 本地类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17884642/