views:

116

answers:

1

The generated App.xaml.cs file contains this

private void Application_Startup(object sender, StartupEventArgs e)
{
  // This will enable you to bind controls in XAML files to WebContext.Current
  // properties
  this.Resources.Add("WebContext", WebContext.Current);

but I cannot figure out how to refer to this object. It seems like I ought to set the page DataContext = "WebContext" and then use it like this

... property="{Binding Path=User.IsAuthenticated}

I'm sure it's straightforward. Can someone clue me in?


Well done, and of course I can't believe I didn't see that. With the addition of a value converter suddenly a tangled mess of state management code becomes declarative, showing and hiding various UI elements according to whether the user is logged in or in various roles without me having to litter my code with trivial conditionals at myriad logical inflection points.

A: 

Try:-

property="{Binding Path=User.IsAuthenticated, Source={StaticResource WebContext}}"

that ought to find it. Its not an object you'd want directly assigned to the DataContext normally, the similarity of the names is co-incidental.

AnthonyWJones