2010-07-01 2 views
2

Silverlight 3의 탐색 API에서 UriMapper 클래스는 대/소문자를 구분합니다. 다음 URI 매핑에 대한Silverlight 3에서 대소 문자가 구별되는 UriMapper 문제

은 "/ 엔티티/123"제대로에 "/Views/EntityEditorPage.xaml?code=123" 하지만 매핑되어
<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> 

"/ 법인/123"를 "/ 조회수 실패합니다 /Entity/123Page.xaml 찾을 수 없음 "예외입니다.

어떻게하면 UriMapper를 대소 문자를 구분하지 않을 수 있습니까?

감사합니다.

답변

2

Safor,

나는 정확히 내 자신의 응용 프로그램에 대한 Anthony의 제안을했습니다. 여기

<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; 
     } 
    } 
} 

행운을 빌어 요, 짐 맥 커디

+0

짐, 코드 주셔서 감사합니다. 그것은 작동합니다! 한 메모 만 있습니다. 소문자로만 매개 변수를 지정해야합니다. -Eugene – Safor

+0

흠, 혼란 스럽네요. 요점은이 UriMapper가 대소 문자를 구별하는 Uri 확인을 수행한다는 것입니다. 소문자로 어떤 매개 변수를 지정하고 있습니까? –

+0

짐, 미안, 네 질문을 놓쳤다. {검색}과 같은 매개 변수를 의미했습니다. 위의 코드를 사용하면 {searchArg} 매개 변수를 사용할 수 없지만 {searcharg} 매개 변수는 작동합니다. 그냥. – Safor

0

당신은 이것을 쉽게 할 수 없습니다. 궁극적으로 자신의 UriMapperBase을 파생시키고 모든 매핑 논리를 직접 수행해야합니다. 단순화 된 매핑을 사용할 수 없다면 할 가치가없는 일입니다.

1

UriMapper 여기

은 XAML은 CustomUriMapper를 사용하도록 수정 정규 표현식을 사용하여 매핑을 "[V | v] iews/EntityEditorPage.xaml? code = {code}"로 변경하면 처음에는 V in view case가 무색이됩니다

+0

공유 해 주셔서 감사합니다 – Safor

+0

위대한 팁. 감사! –

+1

매핑은 "[Vv] iews/EntityEditorPage.xaml? code = {code}"이어야합니다. 그렇지 않으면 URL "| iews/EntityEditorPage.xaml? code = {code}"도 일치합니다. –

관련 문제