locked
Windows 8 RT: XAML Binding to a Singleton RRS feed

  • Question

  • I wanted to do the following at the top of a XAML file:

    <UserControl.DataContext>
        <vm:PreferencesVM.Instance.PreferencesContainer.Url />
    </UserControl.DataContext>

    This results in all kinds of error messages in my Windows 8 Store App:

    • Name 'vm:PreferencesVM.Instance.PreferencesContainer.Url' is not a valid XAML name.
    • Nested properties are not supported: PreferencesVM.Instance.PreferencesContainer.Url
    • The attachable property 'Instance' was not found in type 'PreferencesVM'
    • The property "DataContext" cannot be empty.

    The PreferencesVM class is obviously a Singleton. It would be nice to get some pointers on how to bind to specific Model classes by going through the my Singleton View-Model.

    Thanks...


    Randy

    Friday, November 1, 2013 1:20 PM

Answers

  • you can do from code.

    public MyUserControl()
    
    {
    
    this.InitializeComponents();
    
    DataContext = PreferencesVM.Instance.PreferencesContainer.Url;
    
    
    }
    

    statics are not possible in winrt


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, November 1, 2013 1:37 PM