I'm trying to pass the Interval value to a converter inside the Label template. But somehow the value never gets passed. However, passing Item property value works.
This is the XAML:
<Style TargetType="ig:NumericXAxis">
<Setter Property="Interval" Value="1E15">
<Setter Property="Label">
<Setter.Value>
<DataTemplate>
<TextBlock Foreground= Black}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource NiceDateConverter}">
<Binding Path="Item"/>
<Binding Path="Interval"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
Hello and thank you for posting!
I have reviewed the code snippet you have provided and it seems that using the Item binding you are trying to bind to the data property using the DataContect of the NumericXAxis. As the DataContext is set to the underlying data you can access it using the binding path. On the other hand the Interval is a property that is part of the NumericXAxis and is not presented in the DataContext of the element. This means that it could not be directly bound. You can try to bind to the NumericXAxis name by setting ElementName and then add the path. I hope this will be helpful. Let me know if you need additional assistance.
Thanks Maria. Setting ElementName to the NumericXaxis name works.
However, this is not a very good design since the style is in another file and meant to be used as a library. Therefore, hardcoding the numericXAxis name in the style is not an option.
Is there any other ways I can achieve this?
Hi,
I am glad that the ElementName binding works. Since FindAncestor binding is not supported in Windows Phone apps the other approach I could suggest you is adding a property to your viewmodel which is updated with the current interval of the numeric axis. Then you can bind the text using the underlying data.
I am just checking if you had a chance to look into this and if you would like any further assistance on the matter.