开发者

Accessing the WebContext class in XAML

The generated App.xaml.cs file contains 开发者_JAVA百科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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜