【发布时间】:2020-03-16 08:33:06
【问题描述】:
我对 xaml 不是很熟悉。有人可以帮助我。为什么“名称空间中不存在名称 MercerCataloDataProvider”。据我所知,所有东西都在同一个命名空间中并且应该可用吗?我能做什么?
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WPFOnboarding01
{
public class MercerCatalogDataProvider
{
private MainDataSetTableAdapters.MercerJobCatalogTblTableAdapter adapter;
private MainDataSet dataSet;
public MercerCatalogDataProvider()
{
dataSet = new MainDataSet();
adapter = new MainDataSetTableAdapters.MercerJobCatalogTblTableAdapter();
adapter.Fill(dataSet.MercerJobCatalogTbl);
}
public DataView GetMercerCatalog()
{
return dataSet.MercerJobCatalogTbl.DefaultView;
}
}
}
块引用
<Window x:Class="WPFOnboarding01.TestBinding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFOnboarding01"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="TestBinding" Height="450" Width="800">
<Window.Resources>
<!-- create an instance of our DataProvider class -->
<ObjectDataProvider x:Key="MercerCatalogDataProvider"
ObjectType="{x:Type local:MercerCatalogDataProvider}"/>
<!-- define the method which is invoked to obtain our data -->
<ObjectDataProvider x:Key="MercerJobCatalog"
ObjectInstance="{StaticResource MercerCatalogDataProvider}"
MethodName="GetMercerCatalog"/>
</Window.Resources>
【问题讨论】:
-
尝试忽略它并单击
F5,它运行了吗? XAML 设计器经常出错。或者它还没有合法地构建这个变更项目。 -
尝试将 x:Key="MercerCatalogDataProvider" 更改为其他键名。
-
项目构建,但设计器视图不起作用。
-
X:key 更改没有帮助
-
您使用的是什么版本的 Visual Studio?
标签: c# wpf visual-studio xaml data-binding