MenuViewModel Source (NullReferenceException)

5 posts, 0 answers
  1. Mike
    Mike avatar
    27 posts
    Member since:
    Oct 2007

    Posted 25 Feb 2011 Link to this post

    Hi,

    Trying to load a RadMenu from a .xaml file.  Here is the code

     

     

     

    <UserControl.DataContext>

     

     

     

     

    <local:MenuViewModel Source="/Menu.xaml" />

     

     

     

     

    </UserControl.DataContext>

     


    Now I've placed the menu.xaml file in the ClientBin Folder on the server.  (Next to the .xap file)  I have also marked this file as Content and Copy to Output Directory -> Copy always.

    When I run the program it fails on :

     

     

    using (StreamReader reader = new StreamReader(

     

     

     

     

    Application.GetResourceStream(this.Source).Stream))

     

    NullReferenceException was unhandled by user code.  (Basically saying the file wasn't found)

    Any ideas?



  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 02 Mar 2011 Link to this post

    Hello Mike,

    In our QSF we have set menu.xaml with Build Action - Page and we load them using full URI path (e.g. "/AssemblyName;component/PathToMenu.xamlFile"):
    <local:MenuViewModel Source="/Menu;component/Silverlight/AddRemoveDisable/menu.xaml" />

    Let us know if you need more information.

    Best wishes,
    Hristo
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft banner
  4. MAXX
    MAXX avatar
    5 posts
    Member since:
    Mar 2010

    Posted 18 May 2011 Link to this post

    Hi,
    I created a Menu.Xaml and put it under the project (same location of App.Xaml). I can not access the Xaml as per the code given by telerik. Please guide am i missing some thing in the code...

    When I pass following way, I get "Object reference not set to an instance of an object." l Exception
     <UserControl.DataContext>
            <local:MenuViewModel Source="/ProjectName;ProjectName/Menu.xaml" />
        </UserControl.DataContext>

    And When i pass following way, I get  "Expected relative Uri, found absolute." Exception

    <UserControl.DataContext>
            <local:MenuViewModel Source="pack:/ProjectNames:/Menu.xaml" />
        </UserControl.DataContext>

    Exception comes on following bold lines
    if (this.Source == null) return;
                using (StreamReader reader = new StreamReader(
                    Application.GetResourceStream(this.Source).Stream))
         
          {
                    string xaml = reader.ReadToEnd();
                     this._items = ParseXaml(xaml);
                }

    Please reply,
    Ankur
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 19 May 2011 Link to this post

    Hi Ankur Mittal,

    Your URI is not correct. It need to be in the following pattern: /Assembly;component/Folder/menu.xaml
    If menu.xaml is NOT in folders then you have to skip /Folder part.

    In your case it should be:
    <local:MenuViewModel Source="/ProjectName;component/Menu.xaml" />


    Regards,
    Hristo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. MAXX
    MAXX avatar
    5 posts
    Member since:
    Mar 2010

    Posted 19 May 2011 Link to this post

    Thanks a lot for quick Reply.

    It works now. I found the mistake, I was not using "component/" in the URI. I though it's some folder so i was ignoring this.
    But it works now,

    Smiles

    Ankur
Back to Top
DevCraft banner