I have developed a Silverlight RIA Application. Assume the site link is http://MySilverlightApp
In my main.xaml page I navigate to a different view (e.g Page1). So when I go to http://MySilverlightApp
I get routed to http://MySilverlightApp/#/Page1
In this Page1.xaml I display a list of radio buttons. Each radio button has an ID and upon selecting a radio button I display further things on the page.
I want to pass that ID from url itself, like http://MySilverlightApp/#/Page1?ID=13
Then when my page loads I can grab that ID and select the radio button (with ID 13) and display the material right there.
How can I accomplish this ? I want to grab the string not in code behind but in Page1 view model. (not binding, just want to retrieve value)
Answer: 1
Ok this is what I did.
In my code behind I introduced a property to query and find out if any parameters are passed or not.
private string ParamValue { get { string paramValue = ""; const string paramName = "ID"; if (NavigationContext.QueryString.ContainsKey(paramName)) paramValue = NavigationContext.QueryString[paramName]; return paramValue; } }
In my Loaded Event handler I invoke the view model's public method and pass in the ID. Something like
private void Page1_Loaded(object sender, RoutedEventArgs e) { if (!String.IsNullOrEmpty(ParamValue)) { Page1iewModel page1ViewModel = this.DataContext as Page1ViewModel ; page1ViewModel.SetID(ParamValue); } }
by : Frank Q.http://stackoverflow.com/users/258956
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog