Silverlight - 有没有办法让“可变”? Uri映射?

发布于 2024-11-06 08:53:43 字数 1335 浏览 4 评论 0原文

我正在使用 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}&amp;sort={sort}" />
            <sdk:UriMapping Uri="List/filter={filter}/sort={sort}" MappedUri="/Views/ListPage.xaml?filter={filter}&amp;sort={sort}" />
            <sdk:UriMapping Uri="List/filter={filter}/query={query}/sort={sort}" MappedUri="/Views/ListPage.xaml?filter={filter}&amp;query={query}&amp;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2024-11-13 08:53:43

这就是 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文