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 null;
}
var bindingKey = bindingExpression.DataItem;
I can get this bindingExpression, but the DataItem property is null. I've tested my binding like this
<TextBlock Text="{Binding KeyFromDataContext}" />
and it works fine.
Any ideas?