LeoXue

Hi,

I have stored some data in Application.Properties. Can these data be used as DataContext in xaml binding




Re: Windows Presentation Foundation (WPF) Can Application.Properties be use as DataContext in xaml directly?

Sam Bent - MSFT

In theory, yes. This should work, to set DataContext to the app property with key "xyz":

<StackPanel DataContext="{Binding Source={x:Static Member=Application.Current}, Path=Properties[xyz]}">

In practice, this probably only works if the app property is added before the binding is first evaluated. I don't believe the properties collection raises the right kind of change notifications for this to work dynamically (I can't verify this from where I am right now). So if the binding doesn't see the property the first time, it won't be told to try again. (From code you can nudge it explicitly by calling BindingExpression.UpdateTarget(), but you asked about pure XAML.)