2011-12-10 2 views
0

URI를 리소스 파일에 정의하고 ApplicationBar에서 사용하고 싶습니다.WP7 우리는 정적 리소스로?

WP7 Image Uri as StaticResource

좋아 : 나는 다음과 같은 질문의 첫 번째 대답으로 수행

<ResourceDictionary 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:sys="clr-namespace:System;assembly=System"> 

     <sys:Uri x:Key="MenuButton1">/Images/button1.png</sys:Uri> 
     <sys:Uri x:Key="MenuButton2">/Images/button2.png</sys:Uri> 
    </ResourceDictionary> 

하지만 나를 위해 작동하지 않습니다, XAML 파일은 '수 파싱해라.

Is it possible to supply a type converter for a static resource in WPF?

좋아 :

public class MyStaticResourceExtension : StaticResourceExtension 
{ 
    public IValueConverter Converter { get; set; } 
    public object ConverterParameter { get; set; } 

    public MyStaticResourceExtension() 
    { 
    } 

    public MyStaticResourceExtension(object resourceKey) 
     : base(resourceKey) 
    { 
    } 

    public override object ProvideValue(IServiceProvider serviceProvider) 
    { 
     object value = base.ProvideValue(serviceProvider); 
     if (Converter != null) 
     { 
      Type targetType = typeof(object); 
      IProvideValueTarget target = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; 
      if (target != null) 
      { 
       DependencyProperty dp = target.TargetProperty as DependencyProperty; 
       if (dp != null) 
       { 
        targetType = dp.PropertyType; 
       } 
       else 
       { 
        PropertyInfo pi = target.TargetProperty as PropertyInfo; 
        if (pi != null) 
        { 
         targetType = pi.PropertyType; 
        } 
       } 
      } 
      value = Converter.Convert(value, targetType, ConverterParameter, CultureInfo.CurrentCulture); 
     } 
     return value; 
    } 
} 

그리고 나는 StaticResourceExtension 클래스를 확장하는 다른 해결책을 발견, 다음과 같은 질문의 마지막 대답을 참조 그러나 그것이 창문의 전화기 7에 사용될 수 있는지, 그리고 어떻게 t 그것을 구현, 누군가가 나에게 몇 가지 팁이나 예제를 줄 수 있습니까? 또는 첫 번째 솔루션을 수정하는 데 도움이됩니다. 미리 감사드립니다.

답변

0

ApplicationBar에 데이터 바인딩이 지원되지 않으므로 XAML에서이 작업을 수행하지 않으려합니다.

대신 C#으로 ApplicationBar를 만들어야하는데,이 ApplicationBar는 사용자에게 지역화 기능을 제공합니다.

URL을 정의 할 때 .NET 리소스 파일을 사용하거나 탐색 URL이있는 정적 클래스를 정의하는 것이 좋습니다. URL을 리소스로 정의하는 유일한 이유는 리소스를 다시 사용하려는 것이기 때문에 C#에서 리소스에 액세스해야 할 가능성이 높습니다. 따라서 리소스 파일이 최적의 솔루션.

Here's an example of how to build a ApplicationBar in C#. 또한 투명도 전환과 같은 기능을 추가 할 수 있습니다.

+0

답변 해 주셔서 감사합니다. 사실 현지화 문제를 파악했습니다. 먼저 xaml 파일에서 문자열을 정의하십시오 : ' 새로 고침' 그런 다음 App.xaml에서 파일을 가져온 다음 : '' 그리고 그것은 작동합니다. IconUri 속성에 동일한 작업을 수행하려고하지만 xaml 파일의 정의 된 문자열을 속성에 사용할 수 없으며 xaml 파일에서 Uri를 정의하는 방법을 알지 못합니다. 그래서 그것은 제 질문입니다. – purezhi

+0

''을 사용하십시오. * 다시 *, * 나쁜 생각입니다. –

+0

귀하의 조언에 감사드립니다. – purezhi

0

데이터 템플릿을 사용하면 문제를 파악할 수 있습니다.

+0

감사합니다. 자세한 내용을 알려 주실 수 있습니까? – purezhi