locked
How to bind XAML elements to custom class in Windows Store Apps? RRS feed

  • Question

  • I am working on a Windows Store App and trying to bind some XAML elements to a custom class:

    namespace My.Name.Space {
        public class AppSettings {
            private static AppSettings _instance = new AppSettings();
            public AppSettings Settings { get { return _instance; } 
    
            private static bool SomeOption {
                get {
                    ...
                    return option;
                }
            }
        }
    }

    <!-- ResourceDict will be merged to the Application.Resources -->
    <ResourceDictionary 
       ...
       xmlns:myNS="clr-namespace:My.Name.Space">
    
       <myNS:AppSettings x:Key="AppSettings"/>
    </ResourceDictionary>


    <Button IsEnabled="{Binding Path=Settings.SomeOption, Source={StaticResource AppSettings} .../>

    This works without any problem in a Windows Phone 8 App. But when trying to compile the same code in a Windows Store App the compiler says:

    Unknown Type "AppSettings" in XML-Namespace "clr-namespace:My.Name.Space;assembly=MyAppProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

    So, what can I do to bind a XAML element to my Settings class?

    Wednesday, January 8, 2014 10:01 AM

Answers

  • Hi,

    I solved the issue:

    xmlns:myNS="clr-namespace:My.Name.Space">

    has to be changed to:

    xmlns:myNS="using:My.Name.Space">

    • Marked as answer by Agenor Thursday, January 9, 2014 9:49 AM
    Thursday, January 9, 2014 9:49 AM

All replies

  • I don't think you're doing anything wrong here.  Try restarting Visual Studio - I think this is a bug in the compiler.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, January 8, 2014 1:47 PM
    Moderator
  • Hi,

    I solved the issue:

    xmlns:myNS="clr-namespace:My.Name.Space">

    has to be changed to:

    xmlns:myNS="using:My.Name.Space">

    • Marked as answer by Agenor Thursday, January 9, 2014 9:49 AM
    Thursday, January 9, 2014 9:49 AM