c# - How can I navigate from an "external" .cs file in Silverlight -


i know title isn't clear, i'll try explain myself better.

i've got in mainpage.xaml listbox want populate in way. on purpose, have home.cs file no xaml attached, constructor this:

public home(string sid, listbox lb){...} 

in constructor several post requests webclient and, in uploadstringcompleted method, create several elements, stackpanels, textblocks , hyperlinkbutton.

stackpanel bigpanel = new stackpanel(); bigpanel.width = 456;  hyperlinkbutton hyperlink = new hyperlinkbutton(); hyperlink.content = friend.name + " " + person.surname; hyperlink.click += new routedeventhandler(hyperlink_click); bigpanel.children.add(hyperlink);  lb.items.add(bigpanel); 

and here comes problem. want hyperlink navigate page (friendpage.xaml), can't achieve it, because if try add navigationservice.navigate(new uri("/friendpage.xaml", urikind.relative)) fails, says "an object reference required non-static method navigate".

as far know, code line should in mainpage.xaml, so, there way this? or place hyperlink.click event handler in mainpage.xaml.cs , bind hyperlinkbutton not exist yet?

thank you

you can't use function navigationservice.navigate because navigationservice class here, not object. think have add navigationservice parameters in constructor home, can use then. this:

public void nav(navigationservice anavigationservice) {    anavigationservice.navigate(new uri("")); } 

mainpage should have instance of navigationservice, can pass home

edit: can instance of navigationservice in mainpage this:

//in mainpage navigationservice navservice = navigationservice.getnavigationservice(this); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -