This is a migrated thread and some comments may be shown as answers.

MenuViewModel Source (NullReferenceException)

4 Answers 51 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Admin
Top achievements
Rank 1
Admin asked on 25 Feb 2011, 10:58 AM
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?



4 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 02 Mar 2011, 09:20 AM
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!
0
MAXX
Top achievements
Rank 1
answered on 18 May 2011, 04:22 PM
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
0
Hristo
Telerik team
answered on 19 May 2011, 08:07 AM
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
0
MAXX
Top achievements
Rank 1
answered on 19 May 2011, 09:53 AM
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
Tags
Menu
Asked by
Admin
Top achievements
Rank 1
Answers by
Hristo
Telerik team
MAXX
Top achievements
Rank 1
Share this question
or