开发者

Silverlight - Is there a way to have 'variadic' UriMapping?

开发者 https://www.devze.com 2023-03-05 15:27 出处:网络
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

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 paramet开发者_开发知识库ers, 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}&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>

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().


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消