开发者

Silverlight Usercontrol clr namespace

开发者 https://www.devze.com 2023-02-23 07:40 出处:网络
I\'m building a silverlight MVVM app (using the GalaSoft MVVM light template). The app has some UserControls. Now I have stumbeld across somthing which seems like a namespace issue. The namespaces are

I'm building a silverlight MVVM app (using the GalaSoft MVVM light template). The app has some UserControls. Now I have stumbeld across somthing which seems like a namespace issue. The namespaces are defined in this way:

MyApp.Controls
-> my user controls 
MyApp.View
-> different pages of the app (which use the user controls)
MyApp
-> the namespace of the main page (root namespace)

This works ok as long as I don't give any of the UserControls an x:Name. As soon as an x:Name is defined, the build breaks with the following message:

error CS0426: The type name 'Controls' does not exist in the type 'MyApp.MyApp'

That is realy strange! I can resolve this issue by changing the namespace MyApp.Controls to MyAppControls or by manipulating the generated code, so that the direct reference MyApp.Controls.MyControl is replaced with using MyApp.Controls and then instanciate the control with MyControl (however this will be o开发者_运维问答verwritten again, as soon as I switch to the desgin view).

Does anyone know the reason for this strange behaviour? I would have expected that this is a very common problem?


I think I found the reason: I also had a resource file with the name MyApp. This led to the generation of a class MyApp and therefore the compiler got confused between the class MyApp and the namespace MyApp. I have renamed the Resource file to something different and now the project compiles again.

0

精彩评论

暂无评论...
验证码 换一张
取 消