将 UriMapper.Uri 绑定到 silverlight 4 中的静态资源
是否可以将下面代码中的uri绑定到静态资源?我在资源文件中定义了 url,并希望绑定到该文件,而不是在此处对值进行硬编码。
<navcore:UriMapper x:Key="uriMapper" >
<navcore:UriMapping Uri="Home" MappedUri="/Home.xaml" />
</navcore:UriMapper>
我尝试声明一个静态资源并绑定到它,如下例所示,但它失败了
<Application.Resources>
<local:URLContainer x:Key="URLContainer" />
<navcore:UriMapper x:Key="uriMapper" >
<navcore:UriMapping Uri="Home" MappedUri="{Binding Source={StaticResource URLContainer}, Path=HomeUrl}" />
</navcore:UriMapper>
</Application.Resources>
当我启用 CLR 异常时得到的错误是:
对象类型 “System.Windows.Data.Binding”不能 转换为“System.Uri”类型。
我已将资源文件构造函数公开,并将访问级别也设置为公开。
Is it possible to bind the uri in the code below to a static resource? I have the urls defined in a resource file and wanted to bind to that rather than hardcoding the values here.
<navcore:UriMapper x:Key="uriMapper" >
<navcore:UriMapping Uri="Home" MappedUri="/Home.xaml" />
</navcore:UriMapper>
I tried to declare a static resource and bind to it like in the example below but it failed
<Application.Resources>
<local:URLContainer x:Key="URLContainer" />
<navcore:UriMapper x:Key="uriMapper" >
<navcore:UriMapping Uri="Home" MappedUri="{Binding Source={StaticResource URLContainer}, Path=HomeUrl}" />
</navcore:UriMapper>
</Application.Resources>
Error that i get when i enable CLR exceptions is:
Object of type
'System.Windows.Data.Binding' cannot
be converted to type 'System.Uri'.
I have made the resource file constructor public and set the access level to public too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MappedUri
不是Dependency Property
,因此无法通过 DataBinding 设置它。MappedUri
is not aDependency Property
, thus it can't be set through DataBinding.