WPFLocalizationExtension (Available on CodePlex)을 사용하여 WPF 응용 프로그램의 문자열을 현지화합니다. 이 간단한 MarkupExtension은 다음과 같이 간단한 시나리오에서 잘 작동 :MarkupExtension : 간단한 속성을 DependencyProperty로 변환
<Button Content="{lex:LocText MyApp:Resources:buttonTitle}" />
하지만 같은 좀 더 복잡한 일을 시도로서 내가 바로 붙어있어 (자원 windowTitle = "MyApp v{0}"
으로)
<Window Title="{lex:LocText MyApp:Resources:windowTitle, FormatSegment1={Binding Version}}" />
.
FormatSegment1은 일반 INotifyPropertyChange 속성이므로 아무 것도 바인딩 할 수 없습니다. FormatSegment1이 DependencyProperty 인 경우 가능하므로 소스를 다운로드하고 patch'em을 시도했습니다.
나는MarkupExtension
에서
[MarkupExtensionReturnType(typeof(string))]
public class LocTextExtension : BaseLocalizeExtension<string>
{
// ---- OLD property
//public string FormatSegment1
//{
// get { return this.formatSegments[0]; }
// set
// {
// this.formatSegments[0] = value;
// this.HandleNewValue();
// }
//}
// ---- NEW DependencyProperty
/// <summary>
/// The <see cref="FormatSegment1" /> dependency property's name.
/// </summary>
public const string FormatSegment1PropertyName = "FormatSegment1";
/// <summary>
/// Gets or sets the value of the <see cref="FormatSegment1" />
/// property. This is a dependency property.
/// </summary>
public string FormatSegment1
{
get
{
return (string)GetValue(FormatSegment1Property);
}
set
{
SetValue(FormatSegment1Property, value);
}
}
/// <summary>
/// Identifies the <see cref="FormatSegment1" /> dependency property.
/// </summary>
public static readonly DependencyProperty FormatSegment1Property = DependencyProperty.Register(
FormatSegment1PropertyName,
typeof(string),
typeof(LocTextExtension),
new UIPropertyMetadata(null));
// ...
}
BaseLocalizeExtension
클래스는 상속 수정 : 내가 빌드 할 때
public abstract class BaseLocalizeExtension<TValue> : MarkupExtension, IWeakEventListener, INotifyPropertyChanged
, 나는 보통 "GetValue/SetValue does not exist in current context"
오류가 발생합니다. 나는 클래스를 DependencyObject
에서 상속 받도록하려고 노력하지만 많은 오류가 발생합니다.
MarkupExtension에서 xaml Y 인드 가능 DependencyProperty (또는 Y 인드 가능)를 사용할 수 있습니까? 당신은 당신이 대신 연결된 속성에 갈 수
[** 너무 오래 클래스는 ** DependencyObject에서 파생로, 당신이 그것을 종속성 속성 수 있도록함으로써 DependencyProperty 식별자와 속성을 백업하는 옵션이 있습니다. (http://msdn.microsoft .com/en-us/library/ms753358.aspx) –
@jberger DependencyObject에서 클래스를 파생시키는 경우 어떻게 MarkupExtension으로 동작합니까? –
나는 할 수 있다고 생각하지 않는다. 패턴을 변경해야합니다. Simon의 대답을 수정 해 볼 수 있습니다. –