|
@@ -10,8 +10,6 @@ namespace SyncTrayzor.Localization
|
|
|
|
|
|
public Binding KeyBinding { get; set; }
|
|
|
|
|
|
- public string StringFormat { get; set; }
|
|
|
-
|
|
|
public Binding ValueBinding { get; set; }
|
|
|
|
|
|
public MultiBinding ValueBindings { get; set; }
|
|
@@ -34,66 +32,55 @@ namespace SyncTrayzor.Localization
|
|
|
if (this.ValueBinding != null && this.ValueBindings != null)
|
|
|
throw new ArgumentException("ValueBinding and ValueBindings may not be set at the same time");
|
|
|
|
|
|
- // If we've got no bindings, return a string. If we've got 1 binding, return it. If we've got 2 bindings,
|
|
|
- // return a new MultiBinding.
|
|
|
- // Unfortunately there's no nice way to generalise this...
|
|
|
+ // Most of these conditions are redundent, according to the assertions above. However I'll still state them,
|
|
|
+ // for clarity.
|
|
|
|
|
|
- if (this.KeyBinding == null && this.ValueBinding == null && this.ValueBindings == null)
|
|
|
+ // A static key, and no values
|
|
|
+ if (this.Key != null && this.KeyBinding == null && this.ValueBinding == null && this.ValueBindings == null)
|
|
|
{
|
|
|
// Just returning a string!
|
|
|
- return String.Format(this.StringFormat ?? "{0}", Localizer.Translate(this.Key));
|
|
|
- }
|
|
|
-
|
|
|
- var converter = new LocalizeConverter();
|
|
|
- converter.StringFormat = this.StringFormat;
|
|
|
-
|
|
|
- // Single binding case
|
|
|
- if (this.KeyBinding != null && this.ValueBinding == null && this.ValueBindings == null)
|
|
|
- {
|
|
|
- // Don't set the key, so it'll assume the binding is the key
|
|
|
- converter.Converter = this.KeyBinding.Converter;
|
|
|
- this.KeyBinding.Converter = converter;
|
|
|
- return this.KeyBinding.ProvideValue(serviceProvider);
|
|
|
+ return Localizer.Translate(this.Key);
|
|
|
}
|
|
|
- if (this.KeyBinding == null && this.ValueBinding != null && this.ValueBindings == null)
|
|
|
+ // A static key, and a single value
|
|
|
+ if (this.Key != null && this.KeyBinding == null && this.ValueBinding != null && this.ValueBindings == null)
|
|
|
{
|
|
|
- // Set the key, it'll interpret the binding as the value
|
|
|
- converter.Key = this.Key;
|
|
|
- converter.Converter = this.ValueBinding.Converter;
|
|
|
+ var converter = new StaticKeySingleValueConverter() { Key = this.Key, Converter = this.ValueBinding.Converter };
|
|
|
this.ValueBinding.Converter = converter;
|
|
|
return this.ValueBinding.ProvideValue(serviceProvider);
|
|
|
}
|
|
|
- if (this.KeyBinding == null && this.ValueBinding == null && this.ValueBindings != null)
|
|
|
+ // A static key, and multiple values
|
|
|
+ if (this.Key != null && this.KeyBinding == null && this.ValueBinding == null && this.ValueBindings != null)
|
|
|
{
|
|
|
- converter.Key = this.Key;
|
|
|
- // No converter allowed here
|
|
|
+ var converter = new StaticKeyMultipleValuesConverter() { Key = this.Key, Converter = this.ValueBindings.Converter };
|
|
|
this.ValueBindings.Converter = converter;
|
|
|
return this.ValueBindings.ProvideValue(serviceProvider);
|
|
|
}
|
|
|
-
|
|
|
- MultiBinding multiBinding;
|
|
|
-
|
|
|
- // OK, multibinding cases
|
|
|
- // If this.ValueBindings is set, we'll hijack that
|
|
|
- // Otherwise, we'll create our own
|
|
|
- if (this.ValueBindings != null)
|
|
|
+ // A bound key, no values
|
|
|
+ if (this.Key == null && this.KeyBinding != null && this.ValueBinding == null && this.ValueBindings == null)
|
|
|
{
|
|
|
- // Not setting converter.Converter - no support yet
|
|
|
- multiBinding = this.ValueBindings;
|
|
|
+ var converter = new BoundKeyNoValuesConverter() { Converter = this.KeyBinding.Converter };
|
|
|
+ this.KeyBinding.Converter = converter;
|
|
|
+ return this.KeyBinding.ProvideValue(serviceProvider);
|
|
|
}
|
|
|
- else // this.ValueBinding != null, according to preconditions
|
|
|
+ // A bound key, and one value
|
|
|
+ if (this.Key == null && this.KeyBinding != null && this.ValueBinding != null && this.ValueBindings == null)
|
|
|
{
|
|
|
- multiBinding = new MultiBinding();
|
|
|
+ var converter = new BoundKeyWithValuesConverter();
|
|
|
+ var multiBinding = new MultiBinding() { Converter = converter };
|
|
|
+ multiBinding.Bindings.Add(this.KeyBinding);
|
|
|
multiBinding.Bindings.Add(this.ValueBinding);
|
|
|
+ return multiBinding.ProvideValue(serviceProvider);
|
|
|
+ }
|
|
|
+ // A bound key, and multiple values
|
|
|
+ if (this.Key == null && this.KeyBinding != null && this.ValueBinding == null && this.ValueBindings != null)
|
|
|
+ {
|
|
|
+ var converter = new BoundKeyWithValuesConverter() { ValuesConverter = this.ValueBindings.Converter };
|
|
|
+ this.ValueBindings.Bindings.Insert(0, this.KeyBinding);
|
|
|
+ this.ValueBindings.Converter = converter;
|
|
|
+ return this.ValueBindings.ProvideValue(serviceProvider);
|
|
|
}
|
|
|
|
|
|
- multiBinding.Converter = converter;
|
|
|
- if (this.Key != null) // Can't hit this case if ValueBinding != null
|
|
|
- converter.Key = this.Key;
|
|
|
- else
|
|
|
- multiBinding.Bindings.Insert(0, this.KeyBinding);
|
|
|
-
|
|
|
- return multiBinding.ProvideValue(serviceProvider);
|
|
|
+ throw new Exception("Should never get here");
|
|
|
}
|
|
|
}
|
|
|
}
|