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开发者_Go百科 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"]}" />
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?
精彩评论