markup-extensions

How do I resolve the value of a databinding inside a MarkupExtension?

旧巷老猫 提交于 2019-11-27 23:18:23
I've made a markup extension for translating strings based on a key. Example <TextBlock Text="{Translate myKey}" /> Now I want to be able to use nested bindings for providing my keys. Example: <TextBlock Text="{Translate {Binding KeyFromDataContext}}" /> When I do this I get a System.Windows.Data.Binding object. By calling ProvideValue and passing down the ServiceProvider I can get a BindingExpression: var binding = Key as Binding; if (binding == null) { return null; } var bindingExpression = binding.ProvideValue(_serviceProvider) as BindingExpression; if (bindingExpression == null) { return

MarkupExtension that uses a DataBinding value

懵懂的女人 提交于 2019-11-27 01:46:25
问题 I'm trying to create a WPF MarkupExtension class that provides translated text from my text translation class. The translation stuff works great, but requires a static method call with a text key to return the translated text. Like this: ImportLabel.Text = Translator.Translate("import files"); // will be "Dateien importieren" in de or "Import files" in en Its speciality is that it accepts a counting value to provide better wordings. ImportLabel.Text = Translator.Translate("import n files",

How do I resolve the value of a databinding inside a MarkupExtension?

喜你入骨 提交于 2019-11-26 21:26:35
问题 I've made a markup extension for translating strings based on a key. Example <TextBlock Text="{Translate myKey}" /> Now I want to be able to use nested bindings for providing my keys. Example: <TextBlock Text="{Translate {Binding KeyFromDataContext}}" /> When I do this I get a System.Windows.Data.Binding object. By calling ProvideValue and passing down the ServiceProvider I can get a BindingExpression: var binding = Key as Binding; if (binding == null) { return null; } var bindingExpression =