I create a general-purpose UserControl which looks like a TickBar with labels shown below each tick. The UserControl is used to show timeline or map zoom scale and so on.
The text shown in label is formatted according to the value (its type is double) of tick, which is calculated by Min, Max and TickFrequency of the UserControl, that means, the texts will not be bound to a ItemsSource (I know how to format texts outside UserControl, and then pass them into UserControl, but it not my case).
Because the format of texts is determined by the user of the UserControl, for example, when UserControl is used as a timeline, show text like "00:00 01:00 02:00 ...", but when used as a map zoom scale, shown text like "1x 2x 4x 8x".
My solution is to pass a IValueConverter into the UserControl through a Dependency Property. My first try is to write like this (LabelConverter is a Dependency Property of MyUserControl):
MyUserControl.xaml
<UserControl Name="usercontrol">
...
<TextBlock Text="{Binding Value, Converter={Binding LabelConverter, ElementName=usercontrol}}" />
...
</UserControl>
MainWindow.xaml
<uc:MyUserControl LabelConverter="{StaticResource TickToStringConverter}" />
But failed because Binding.Converter of TextBlock.Text is not a Dependency Property, we can't Binding it to a property. And we can't use Converter={StaticResource ...} because we can't define a converter resource in UserControl because it is determined by user.
So, How to use this IValueConterter property in XAML? Or any other solution?