Silverlight 在XAML中访问WebContext类
生成的App.xaml.cs文件包含以下内容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); 但我不知道
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的对象。通常,名称的相似性是附带的