Silverlight - 有没有办法让“可变”? Uri映射?
我正在使用 Silverlight 导航框架,其中有一个框架,其中有一个 UriMapper
。由于我的一个页面可以有多个参数,因此我希望有一种通配符或可变参数映射,以避免创建所有参数组合。
这是只有三个参数的样子,并且省略了一些组合:
<sdk:Frame>
<sdk:Frame.UriMapper>
<sdk:UriMapper x:Name="uriMapper">
<sdk:UriMapping Uri="List/query={query}/sort={sort}" MappedUri="/Views/ListPage.xaml?query={query}&sort={sort}" />
<sdk:UriMapping Uri="List/filter={filter}/sort={sort}" MappedUri="/Views/ListPage.xaml?filter={filter}&sort={sort}" />
<sdk:UriMapping Uri="List/filter={filter}/query={query}/sort={sort}" MappedUri="/Views/ListPage.xaml?filter={filter}&query={query}&sort={sort}" />
<sdk:UriMapping Uri="List/sort={sort}" MappedUri="/Views/ListPage.xaml?sort={sort}" />
<sdk:UriMapping Uri="{}{Page}" MappedUri="/Views/{Page}Page.xaml" />
</sdk:UriMapper>
</sdk:Frame.UriMapper>
</sdk:Frame>
我想要一种用一行将所有可能的参数写入“列表”页面的方法,因为它们都遵循相同的规则。类似的东西(这不起作用):
<sdk:UriMapping Uri="List/{params}" MappedUri="/Views/ListPage.xaml?{params}" />
那么,有没有办法在 Silverlight 中做到这一点?
编辑:如果其他一切都失败,我可能会回退到在代码中生成映射,这看起来比几十行 XAML 更难看。
EDIT2:或者只是忘记映射 URI,而将真实的页面名称传递给 Navigate()。
I'm using the Silverlight Navigation framework, with a single Frame in which I have a UriMapper
. As I can have several parameters for one of my pages, I'd like a have a kind of wildcard or variadic mapping to avoid creating all the combinations of parameters.
Here is what it looks like with only three parameters, and some combinations omitted:
<sdk:Frame>
<sdk:Frame.UriMapper>
<sdk:UriMapper x:Name="uriMapper">
<sdk:UriMapping Uri="List/query={query}/sort={sort}" MappedUri="/Views/ListPage.xaml?query={query}&sort={sort}" />
<sdk:UriMapping Uri="List/filter={filter}/sort={sort}" MappedUri="/Views/ListPage.xaml?filter={filter}&sort={sort}" />
<sdk:UriMapping Uri="List/filter={filter}/query={query}/sort={sort}" MappedUri="/Views/ListPage.xaml?filter={filter}&query={query}&sort={sort}" />
<sdk:UriMapping Uri="List/sort={sort}" MappedUri="/Views/ListPage.xaml?sort={sort}" />
<sdk:UriMapping Uri="{}{Page}" MappedUri="/Views/{Page}Page.xaml" />
</sdk:UriMapper>
</sdk:Frame.UriMapper>
</sdk:Frame>
I'd like a way to write all the possible parameters to the 'List' Page with a single line, as they all follow the same rule. Something like (which doesn't work):
<sdk:UriMapping Uri="List/{params}" MappedUri="/Views/ListPage.xaml?{params}" />
So, is there a way to do that in Silverlight?
EDIT: If everything else fails, I might fallback to generating the mapping in code, which would look less ugly than dozens of XAML lines.
EDIT2: Or just forget about mapping URIs and just pass the real page name to Navigate().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是 Silverlight 导航框架的失败之处,也是我不在生产应用程序中使用它的重要原因之一。也就是说,在 Silverlight 4 中,您可以使用 INavigationContentLoader 以编程方式将所有不同的参数映射到其正确的视图,并创建您自己的更强大的映射器类。
另请注意,目前 Windows Phone 7 中不提供此功能(我看到您进行了大量 iOS 开发,因此想指出这一点)。如果我没记错的话,它应该在 Windows Phone 的 Mango 更新中提供,该更新应该在下个月左右向开发者提供,并在今年年底向消费者提供。
查看这些链接以获取更多信息:
http://blogs.msdn.com/ b/dphill/archive/tags/helix/
http://www.davidpoll。 com/2009/11/30/opening-up-silverlight-4-navigation-introduction-to-inavigationcontentloader/
This is where the Silverlight navigation framework falls flat on its face, and one of the big reasons I don't use it in production applications. That being said, in Silverlight 4 you can use the
INavigationContentLoader
to programmatically map all the different params to their correct view, and create your own mapper class that is more robust.Also note, that this is not available in Windows Phone 7 currently (I see you do a lot of iOS dev, so wanted to point that out). If I recall correctly, it should be available in the Mango update for Windows Phone, which should be available in the next month or so for developers and end of this year for consumers.
Check out these links for more info:
http://blogs.msdn.com/b/dphill/archive/tags/helix/
http://www.davidpoll.com/2009/11/30/opening-up-silverlight-4-navigation-introduction-to-inavigationcontentloader/