WPF xmlns:local="clr-namespace:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12749029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:32:08  来源:igfitidea点击:

WPF xmlns:local="clr-namespace:

wpfvisual-studio-2010xaml

提问by StephanM

I am having problems with Namespaces, I seem to be chasing the error around and now I am down to one left that I don't understand. All my files have the same namespace, I don't really think I need more then one for a small program.

我在命名空间方面遇到了问题,我似乎在四处寻找错误,现在我只剩下一个我不明白的地方。我所有的文件都具有相同的命名空间,我真的不认为我需要一个小程序。

Example.xaml
<UserControl x:Class="Example"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
         xmlns:chart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Chart"
         xmlns:chartView="clr-namespace:Telerik.Windows.Controls.ChartView;assembly=Telerik.Windows.Controls.Chart"
         xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"
         xmlns:local="clr-namespace:Example.ExampleViewModel"
         xmlns:System="clr-namespace:System;assembly=mscorlib">
<telerikQuickStart:QuickStart.ExampleHeader>
    <TextBlock Text="Atlanta Sales Dashboard" Margin="8" />
</telerikQuickStart:QuickStart.ExampleHeader>
<UserControl.DataContext>
    <local:ExampleViewModel />
</UserControl.DataContext> /


ExampleViewModel.cs

using System;
using System.Collections.ObjectModel;
using System.Linq;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Map;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Resources;
using System.Xml;



namespace Example.ExampleViewModel
{
public class ExampleViewModel : ViewModelBase

The ExampleViewModel is still giving me the following errors.

ExampleViewModel 仍然给我以下错误。

 Error  1   The name "ExampleViewModel" does not exist in the namespace "clr-namespace:Example.ExampleViewModel".   D:\visual studio 12\Projects\Map1\Map1\Example.xaml 14  9   Map1
    Error   2   The namespace '<global namespace>' already contains a definition for 'Example'  D:\visual studio 12\Projects\Map1\Map1\obj\x86\Debug\Example.g.cs   62  22  Map1

采纳答案by StephanM

After searching this out I finally cleaned that error out with the help from the following: http://windowsclient.net/learn/video.aspx?v=31429

搜索完后,我终于在以下帮助下清除了该错误:http: //windowsclient.net/learn/video.aspx?v=31429

But this moved me to another error that i am going to contact Telerik on. It seems they are using a control which is in another namespace.

但这让我想到了另一个错误,我将联系 Telerik。似乎他们正在使用另一个命名空间中的控件。

Thanks

谢谢

回答by Bernard

Please review all of your namespaces. Some of them appear to be incorrect. Ensure that all of the classes you intend to reference have the correct namespace (including assembly) defined.

请检查您的所有命名空间。其中一些似乎是不正确的。确保您要引用的所有类都定义了正确的命名空间(包括程序集)。

I suggest you start with only a few namespaces, ensure that they work without error, and then gradually add all of the required namespaces.

我建议你从几个命名空间开始,确保它们正常工作,然后逐渐添加所有需要的命名空间。

回答by Raúl Ota?o

It seems to be an error in the xaml definition, see:

好像是xaml定义中的错误,见:

the control class is:

控制类是:

<UserControl x:Class="Telerik.Windows.Examples.Map.SalesDashboard.Example"

but you are defining the "local" namesapce exactly with the same name:

但是您正在使用完全相同的名称定义“本地”名称空间:

xmlns:local="clr-namespace:Telerik.Windows.Examples.Map.SalesDashboard.Example

i think there should be an error in your xaml, or in your class definitions, try this...

我认为您的 xaml 或类定义中应该有错误,试试这个...