在WPF中,命名空间的工作方式出现问题. [英] In WPF how do namespaces work, I'm having a problem.
问题描述
我是VB.net的新手,也是wpf的新手.尽管我喜欢到目前为止所看到的,但是我在命名空间方面遇到了麻烦.
据我所知,是否有人对它们有全面的指导,或者至少有一些指示(见到很多示例工作原理相同),但是其中一些似乎无缘无故地出现了,但我不知道为什么.我正在使用VS2008,尽管我看到的都是正确的,但我却遇到了这些错误.
I''m pretty new to VB.net, and very new to wpf. althought i like what i see so far, i''m having trouble with namespaces.
Does anyone have a comprehensive guide on them, or at least some pointers, as far as i can tell i''m doing it right (seen loads of examples that work the same way) but some of them seem to break for no reason, but i cant work out why. I''m using VS2008, and i''m getting these errors, despite as far as i can see, everything being correct.
Error 1 The tag 'View' does not exist in XML namespace 'clr-namespace:MainApp'. Line 344 Position 3. C:\Users\caddy\Desktop\proj\Proj\WpfApplication1\WpfApplication1\Window1.xaml 344 3 MainApp
Error 2 The type 'my:View' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. C:\Users\caddy\Desktop\proj\Proj\WpfApplication1\WpfApplication1\Window1.xaml 344 3 MainApp
这两件事肯定以与其他项目相同的方式出现,并且不明白为什么会有所不同.
both things definatly appear in the same way as may other projects, adn i cent see why this wuld be different.
推荐答案
命名空间完全无关紧要.它们比C ++琐碎得多,并且不能像在C ++中那样工作.我认为您正在尝试像使用它们一样使用它们.在VB.NET和C#中,您只需在代码的顶部放置一个using语句,或者使用点限定范围:my.View,而不是my:View.
Namespaces are utterly trivial. They are far more trivial than C++, and don''t work the way they do in C++. I think you''re trying to use them as if they were. In VB.NET and C#, you just put a using statement at the top of your code, or you scope with dots: my.View, not my:View.
您好,谢谢您的答复,这是Xaml本身,而不是VB代码,因此例如
Hi, Thanks for your reply, This is in the Xaml itself, rather than the VB Code, so for instance
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:MainApp"
Title="Window1" Width="600" Height="450">
<my:View x:Name="test" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"/>
</Window>
即使当我将其更改为sometihng时,也是如此:
Even when i change this to sometihng like this:
xmlns:my="clr-namespace:MainApp.BOB"
在vb代码中具有对应的"BOB"命名空间.
现在让我沮丧了大约三天.
还要道歉来打字.
with a corresponding "BOB" namespace in the vb code.
its been frustrating me for about 3 days now.
Also Apologies for terrable typing.
这篇关于在WPF中,命名空间的工作方式出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!