Reputation: 10624
I have a view model with an ID that I'd like to be able to set from a querystring. Is there a way in XAML to set the value of a property to a querystring value? Here's the current XAML:
<local:DetailsViewModel x:Key="viewModel" DetailsID="1" />
Is there XAML that is effectively something like this?
<local:DetailsViewModel x:Key="viewModel" DetailsID="{Binding HtmlDocument.Querystring["id"]}" />
Upvotes: 1
Views: 515
Reputation: 70170
To access the querystring in code you can use the following:
var query = System.Windows.Browser.HtmlPage.Document.QueryString;
As you can see, HtmlPage is a static class. However, binding to static instances is not possible in Silverlight (in WPF you can use {x:Static}).
On another note, most people use regular CLR objects for their ViewModels, rather than DependencyObjects with DependencyProperties, which is thought of as overkill. Therefore, you cannot create a ViewModel with a property that is bound!
Is there any reason why you don't want to do this in code?
Upvotes: 1