Чувствительная к регистру проблема UriMapper в Silverlight 3 - PullRequest
2 голосов
/ 01 июля 2010

В API навигации Silverlight 3 класс UriMapper чувствителен к регистру.Для следующего отображения uri

<nav:Frame Source="/Home">
  <nav:Frame.UriMapper>
    <uriMapper:UriMapper>
      <uriMapper:UriMapping
        Uri=""
        MappedUri="/Views/HomePage.xaml"/>
      <uriMapper:UriMapping
        Uri="/entity/{code}"
        MappedUri="/Views/EntityEditorPage.xaml?code={code}"/>
      <uriMapper:UriMapping
        Uri="/{pageName}"
        MappedUri="/Views/{pageName}Page.xaml"/>
    </uriMapper:UriMapper>
  </nav:Frame.UriMapper>
</nav:Frame>

"/ entity / 123" правильно отображается на "/Views/EntityEditorPage.xaml?code=123", но "/ Entity / 123" завершится неудачно с "/Views / Entity / 123Page.xaml not found "исключение.

Как включить UriMapper без учета регистра?

Спасибо.

Ответы [ 3 ]

2 голосов
/ 27 июля 2010

Safor,

Я сделал именно то, что предложил Энтони для моего собственного заявления.

Вот ваш XAML, модифицированный для использования CustomUriMapper:

<nav:Frame Source="/Home">
    <nav:Frame.UriMapper>
        <app:CustomUriMapper>
            <app:CustomUriMapping Uri="" MappedUri="/Views/HomePage.xaml"/>
            <app:CustomUriMapping Uri="/entity/{code}" MappedUri="/Views/EntityEditorPage.xaml?code={code}"/>
            <app:CustomUriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}Page.xaml"/>
        </app:CustomUriMapper>
    </nav:Frame.UriMapper>
</nav:Frame>

Вот код для классов CustomUriMapping и CustomUriMapper:

using System;
using System.Collections.ObjectModel;
using System.Windows.Markup;
using System.Windows.Navigation;

namespace YourApplication
{
    // In XAML:
    // <app:CustomUriMapper>
    //     <app:CustomUriMapping Uri="/{search}" MappedUri="/Views/searchpage.xaml?searchfor={search}"/>
    // </app:CustomUriMapper>

    public class CustomUriMapping
    {
        public Uri Uri { get; set; }
        public Uri MappedUri { get; set; }

        public Uri MapUri(Uri uri)
        {
            // Do the uri mapping without regard to upper or lower case
            UriMapping _uriMapping = new UriMapping() { Uri = (Uri == null || string.IsNullOrEmpty(Uri.OriginalString) ? null : new Uri(Uri.OriginalString.ToLower(), UriKind.RelativeOrAbsolute)), MappedUri = MappedUri };
            return _uriMapping.MapUri(uri == null || string.IsNullOrEmpty(uri.OriginalString) ? null : new Uri(uri.OriginalString.ToLower(), UriKind.RelativeOrAbsolute));
        }
    }

    [ContentProperty("UriMappings")]
    public class CustomUriMapper : UriMapperBase
    {
        public ObservableCollection<CustomUriMapping> UriMappings { get { return m_UriMappings; } private set { m_UriMappings = value; } }
        private ObservableCollection<CustomUriMapping> m_UriMappings = new ObservableCollection<CustomUriMapping>();

        public override Uri MapUri(Uri uri)
        {
            if (m_UriMappings == null)
                return uri;

            foreach (CustomUriMapping mapping in m_UriMappings)
            {
                Uri mappedUri = mapping.MapUri(uri);
                if (mappedUri != null)
                    return mappedUri;
            }

            return uri;
        }
    }
}

Удачи, Джим МакКарди

1 голос
/ 30 октября 2010

UriMapper использует регулярное выражение, попробуйте изменить ваше отображение на «[V | v] iews / EntityEditorPage.xaml? Code = {code}», для начала это сделает V в случае незаметного

0 голосов
/ 06 июля 2010

Вы не можете сделать это легко. В конечном итоге вам нужно будет получить свой собственный UriMapperBase и выполнить всю логику отображения самостоятельно. Это, вероятно, не стоит делать, если вы не можете использовать некоторые упрощенные отображения.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...