A TwoWay or OneWayToSource binding cannot work with the read-only Value property of the WpfLocalization.Localization.KeyLocalizationListener type
<TextBox x:Name="textBox_date" IsReadOnly="True" HorizontalAlignment="Stretch" Text="{l:Localization Key=The_current_date}" VerticalAlignment="Top" Margin="0,172,0,0"/> namespace WpfLocalization.Localization { /// <summary> /// Π Π°ΡΡΠΈΡΠ΅Π½ΠΈΠ΅ ΡΠ°Π·ΠΌΠ΅ΡΠΊΠΈ, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΡΡ ΡΡΡΠΎΠΊΡ ΠΏΠΎ ΠΊΠ»ΡΡΡ ΠΈΠ»ΠΈ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠ΅ /// </summary> [ContentProperty(nameof(ArgumentBindings))] public class LocalizationExtension : MarkupExtension { private Collection<BindingBase> _arguments; public LocalizationExtension() { } public LocalizationExtension(string key) { Key = key; } /// <summary> /// ΠΠ»ΡΡ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΠΎΠΉ ΡΡΡΠΎΠΊΠΈ /// </summary> public string Key { get; set; } /// <summary> /// ΠΡΠΈΠ²ΡΠ·ΠΊΠ° Π΄Π»Ρ ΠΊΠ»ΡΡΠ° Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΠΎΠΉ ΡΡΡΠΎΠΊΠΈ /// </summary> public Binding KeyBinding { get; set; } /// <summary> /// ΠΡΠ³ΡΠΌΠ΅Π½ΡΡ ΡΠΎΡΠΌΠ°ΡΠΈΡΡΠ΅ΠΌΠΎΠΉ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΡΠΉ ΡΡΡΠΎΠΊΠΈ /// </summary> public IEnumerable<object> Arguments { get; set; } /// <summary> /// ΠΡΠΈΠ²ΡΠ·ΠΊΠΈ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠΎΠ² ΡΠΎΡΠΌΠ°ΡΠΈΡΡΠ΅ΠΌΠΎΠΉ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΡΠΉ ΡΡΡΠΎΠΊΠΈ /// </summary> public Collection<BindingBase> ArgumentBindings { get { return _arguments ?? (_arguments = new Collection<BindingBase>()); } set { _arguments = value; } } public override object ProvideValue(IServiceProvider serviceProvider) { if (Key != null && KeyBinding != null) throw new ArgumentException($"ΠΠ΅Π»ΡΠ·Ρ ΠΎΠ΄Π½ΠΎΠ²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎ Π·Π°Π΄Π°ΡΡ {nameof(Key)} ΠΈ {nameof(KeyBinding)}"); if (Key == null && KeyBinding == null) throw new ArgumentException($"ΠΠ΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ Π·Π°Π΄Π°ΡΡ {nameof(Key)} ΠΈΠ»ΠΈ {nameof(KeyBinding)}"); if (Arguments != null && ArgumentBindings.Any()) throw new ArgumentException($"ΠΠ΅Π»ΡΠ·Ρ ΠΎΠ΄Π½ΠΎΠ²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎ Π·Π°Π΄Π°ΡΡ {nameof(Arguments)} ΠΈ {nameof(ArgumentBindings)}"); var target = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget)); if (target.TargetObject.GetType().FullName == "System.Windows.SharedDp") return this; // ΠΡΠ»ΠΈ Π·Π°Π΄Π°Π½Ρ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠ° ΠΊΠ»ΡΡΠ° ΠΈΠ»ΠΈ ΡΠΏΠΈΡΠΎΠΊ ΠΏΡΠΈΠ²ΡΠ·ΠΎΠΊ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠΎΠ², // ΡΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ BindingLocalizationListener if (KeyBinding != null || ArgumentBindings.Any()) { var listener = new BindingLocalizationListener(); // Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΏΡΠΈΠ²ΡΠ·ΠΊΡ Π΄Π»Ρ ΡΠ»ΡΡΠ°ΡΠ΅Π»Ρ var listenerBinding = new Binding { Source = listener }; var keyBinding = KeyBinding ?? new Binding { Source = Key }; var multiBinding = new MultiBinding { Converter = new BindingLocalizationConverter(), ConverterParameter = Arguments, Bindings = { listenerBinding, keyBinding } }; // ΠΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ Π²ΡΠ΅ ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΠ΅ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠΈ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠΎΠ² foreach (var binding in ArgumentBindings) multiBinding.Bindings.Add(binding); var value = multiBinding.ProvideValue(serviceProvider); // Π‘ΠΎΡ
ΡΠ°Π½ΡΠ΅ΠΌ Π²ΡΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠΈ Π² ΡΠ»ΡΡΠ°ΡΠ΅Π»Π΅ listener.SetBinding(value as BindingExpressionBase); return value; } // ΠΡΠ»ΠΈ Π·Π°Π΄Π°Π½ ΠΊΠ»ΡΡ, ΡΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ KeyLocalizationListener if (!string.IsNullOrEmpty(Key)) { var listener = new KeyLocalizationListener(Key, Arguments?.ToArray()); // ΠΡΠ»ΠΈ Π»ΠΎΠΊΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Π½Π°Π²Π΅ΡΠ°Π½Π° Π½Π° DependencyProperty ΠΎΠ±ΡΠ΅ΠΊΡΠ° DependencyObject if ((target.TargetObject is DependencyObject && target.TargetProperty is DependencyProperty) || target.TargetObject is Setter) { var binding = new Binding(nameof(KeyLocalizationListener.Value)) { Source = listener, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; return binding.ProvideValue(serviceProvider); } // ΠΡΠ»ΠΈ Π»ΠΎΠΊΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Π½Π°Π²Π΅ΡΠ°Π½Π° Π½Π° Binding, ΡΠΎ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌ ΡΠ»ΡΡΠ°ΡΠ΅Π»Ρ var targetBinding = target.TargetObject as Binding; if (targetBinding != null && target.TargetProperty != null && target.TargetProperty.GetType().FullName == "System.Reflection.RuntimePropertyInfo") { targetBinding.Path = new PropertyPath(nameof(KeyLocalizationListener.Value)); targetBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; return listener; } // ΠΠ½Π°ΡΠ΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΡΡ ΡΡΡΠΎΠΊΡ return listener.Value; } return null; } } }
{l:Localization}problem. What is inside? - VladD