I have an interesting MarkupExtension
use case serving an IValueConverter
, which accepts an int
(Counter
), and maps that to an L10N formatted localization. I am not certain how to best approach solving it, whether it is even solvable for that matter.
<TextBlock Text="{Binding Path=Counter, Converter={wpf:GettextFormatConverter Binding string format support: {0:n0}}}" HorizontalAlignment="Center" />
In and of itself, the mapping is formatting correctly, but I want to gain awareness of the XAML content area in the following way.
I can add a simple MarkupExtension property DomainName
, which I will probably do anyway, but it just feels awkward, i.e.
<TextBlock Text="{Binding Path=Counter, Converter={wpf:GettextFormatConverter Binding string format support: {0:n0}}, DomainName=Example}" HorizontalAlignment="Center" />
I would like to discern DomainName
from a parent L10N content wrapper, i.e.
<LocalizationContent DomainName="Example">
<TextBlock Text="{Binding Path=Counter, Converter={wpf:GettextFormatConverter Binding string format support: {0:n0}}}" HorizontalAlignment="Center" />
</LocalizationContent>
Which I can easily do when the extension is directly mapped into the control text or content.
<LocalizationContent DomainName=Example>
<TextBlock Text="{wpf:Gettext Varying case example:}" HorizontalAlignment="Center" />
</LocalizationContent>
In this case, TargetObject
and corresponding TargetProperty
are DependencyObject
and DependencyProperty
, respectively. Which lends itself to discovering the FrameworkElement
parent.
But not in the primary target use case. The problem is, the TargetObject
in this use case is a Binding
, and not the parent TextBlock
FrameworkElement
. The rub is this: how best to identify that TextBlock
(FrameworkElement
) from the ProvideValue
context? Without necessarily having to jump into XAML service providers, things of this nature.