开发者

How can I bind a querystring to a property on my view model in silverlight?

开发者 https://www.devze.com 2023-02-08 21:52 出处:网络
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:

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号