URI를 리소스 파일에 정의하고 ApplicationBar에서 사용하고 싶습니다.WP7 우리는 정적 리소스로?
좋아 : 나는 다음과 같은 질문의 첫 번째 대답으로 수행
<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 그것을 구현, 누군가가 나에게 몇 가지 팁이나 예제를 줄 수 있습니까? 또는 첫 번째 솔루션을 수정하는 데 도움이됩니다. 미리 감사드립니다.
답변 해 주셔서 감사합니다. 사실 현지화 문제를 파악했습니다. 먼저 xaml 파일에서 문자열을 정의하십시오 : ' 새로 고침 core : String>' 그런 다음 App.xaml에서 파일을 가져온 다음 : ' ' 그리고 그것은 작동합니다. IconUri 속성에 동일한 작업을 수행하려고하지만 xaml 파일의 정의 된 문자열을 속성에 사용할 수 없으며 xaml 파일에서 Uri를 정의하는 방법을 알지 못합니다. 그래서 그것은 제 질문입니다. –
purezhi
''을 사용하십시오. * 다시 *, * 나쁜 생각입니다. –
귀하의 조언에 감사드립니다. – purezhi