Do I need two xmlns:local="clr-namespace"?
Asked Answered
T

3

11

Here's the setup I'd like to have for my Windows Phone app, using c# in visual studio 2010:

**MainPage.xaml** contains elements that have an attached property, whose values will be modifiable/savable by the user.

**MainPage.xaml.cs**       

first Namespace is PhoneApp ,inside it is a nested namespace called MyNamespace that declares the dependency property. it works(Thanks, Daniel)

**SettingsSample.xaml** that will allow users to change the values of the attached property in MainPage.xaml for any element and automatically save the change.

**AppSettings.cs** a class that exactly reproduces the first listing in this tutorial: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769510%28v=vs.105%29.aspx

That page declares the same NameSpace as the MainPage.xaml.cs (PhoneApp), then a public class called AppSettings that is exactly like in the tutorial.

To join everything together, I did:

**MainPage.xaml**

xmlns:local="clr-namespace:PhoneApp.MyNamespace"

I needed this to use the attached property

<phone:PhoneApplicationPage.Resources>
    <local:AppSettings x:Key="appSettings"></local:AppSettings>
</phone:PhoneApplicationPage.Resources>

Confusion begins. On the tutorial, they put this on the settings page, but I guess because their settings page is also the one including the elements with the properties that are bound to the saved settings. Mine are on the mainpage, so I put this here. To recap, My settings page will only use methods to change/save these values(and the methods are in AppSettings.cs). Also in the tutorial they add this:

xmlns:local="clr-namespace:SettingsSample"

to the Setting Page(where "SettingsSample" is the Namespace containing declaration/get-Set methods of savable settings) but, for the same reason, I tried to put it on the mainpage, but only one declaration of xmlns:local can be done. I tried several things to put them one after the other, but it doesn't work. This is the key to the two errors I'll list below.

Some elements of mainpage have this, for exemple:

local:MyClass.Son="{Binding Source={StaticResource appSettings}, Path=son1, Mode=TwoWay}" Style="{StaticResource pad}"

"Son" is the attached property

Ok, so I tried different different things but it never worked. The best I could get was in MainPage.xaml that it couldn't create an instance of AppSettings. Now it's different, I have the two errors.

-the type local:AppSettings was not found

-the tag AppSettings does not exist in xml namespace PhoneApp.MyNamespace.

I think this is because I didn't put the

 xmlns:local="clr-namespace:PhoneApp"

But I already have

xmlns:local="clr-namespace:PhoneApp.MyNamespace"

and can't put both.(and to me, one is included in the other...) The reason I listed all the ins and out of the situation is because I kind of expect other troubles after I get through this. I hope this message is clear enough for someone to help me. I spent so much time on it that I begin to loose my mind, so I hope there's no stupid mistake. Of course, I can add any information needed. Thank you for reading anyway!

Tarratarradiddle answered 18/2, 2013 at 3:44 Comment(0)
D
8

"local" in this case is simply a friendly name for the namespace you are referencing. It is completely interchangeable.

Disject answered 18/2, 2013 at 7:7 Comment(0)
E
14

These are XML namespace mappings. With the following:

xmlns:local="clr-namespace:PhoneApp"

The local part is the XML namespace, whilst PhoneApp is the namespace from your .NET code. With this definition in place you can then reference classes from this namespace in XML as follows:

<local:MyClassInPhoneAppNamespace/>

Because the local part is simply a name, you can change it to whatever you like:

xmlns:fish="clr-namespace:PhoneApp"

And use as follows:

<fish:MyClassInPhoneAppNamespace/>

This should mean that you no longer have collisions.

Eddi answered 18/2, 2013 at 7:34 Comment(2)
TriggerPin and ColinE, THANK YOU. I didn't know that. To my surprise, it works now. I'll check TriggerPin's post as the answer and will leave the word "fish" in my app as a tribute to ColinE !Tarratarradiddle
Thanks, i could not ask for a better tribute than that!Eddi
D
8

"local" in this case is simply a friendly name for the namespace you are referencing. It is completely interchangeable.

Disject answered 18/2, 2013 at 7:7 Comment(0)
R
2

I was in need to import two local in same file as below

xmlns:local="clr-namespace:Generique.Views.Assets.Entries"
xmlns:local="clr-namespace:Generique.Views.Assets"

I just change the name and it works fine

xmlns:local="clr-namespace:Generique.Views.Assets.Entries"
xmlns:footer="clr-namespace:Generique.Views.Assets"
Rahman answered 24/4, 2019 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.