Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 在XAML中访问WebContext类_Silverlight_Silverlight 4.0_Webcontext - Fatal编程技术网

Silverlight 在XAML中访问WebContext类

Silverlight 在XAML中访问WebContext类,silverlight,silverlight-4.0,webcontext,Silverlight,Silverlight 4.0,Webcontext,生成的App.xaml.cs文件包含以下内容 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); 但我不知道

生成的App.xaml.cs文件包含以下内容

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);
但我不知道如何引用这个对象。似乎我应该设置页面DataContext=“WebContext”,然后像这样使用它

... property="{Binding Path=User.IsAuthenticated}
我相信这很简单。有人能给我提供线索吗


干得好,当然我不敢相信我没有看到。随着一个值转换器的加入,一堆混乱的状态管理代码突然变成了声明性的,根据用户是否登录或担任不同的角色来显示和隐藏各种UI元素,而无需我在无数逻辑转折点用琐碎的条件来乱丢代码。

试试:-

property="{Binding Path=User.IsAuthenticated, Source={StaticResource WebContext}}"
那应该找到了。它不是您希望直接分配给DataContext的对象。通常,名称的相似性是附带的