I am working on some custom XamDataChart controls and in part of it I need some custom tool-tips. I can do it in XAML like this:
<ig:XamDataChart x:Name="xamDataChart">
<ig:XamDataChart.Axes>
<ig:NumericXAxis x:Name="numericXAxis"/>
<ig:NumericYAxis x:Name="numericYAxis"/>
</ig:XamDataChart.Axes>
<ig:XamDataChart.Series>
<ig:ScatterLineSeries x:Name="observationSeries" Thickness="1" MarkerType="Circle" IsHighlightingEnabled="True">
<ig:ScatterLineSeries.ToolTip>
<StackPanel Orientation="Vertical">
<TextBlock Margin="2" Text="{Binding Item.XValue, StringFormat=BinCenter: {0,9:###0.000}}" VerticalAlignment="Stretch" />
<TextBlock Margin="2" Text="{Binding Item.YValue, StringFormat=BinValue: {0,10:##########}}" VerticalAlignment="Stretch" />
</StackPanel>
</ig:ScatterLineSeries.ToolTip>
</ig:ScatterLineSeries>
</ig:XamDataChart.Series>
</ig:XamDataChart>
In above code, XValue and YValue are properties of a custom data container class which I've made.
Now due to multiple reasons I want to do this in code behind (one good reason is being able to use nameof operator). So the question is how can I achieve this goal?
Hello Dariush,
Thank you for your post.
I have attached a sample project in which I essentially build the XAML chart that you have referenced in this post programmatically. It sounds like the issues that you are having are mostly binding related. To set this up, you need to use the SetBinding method on the TextBlocks that you are setting in your tooltip in this case. This method will take a DependencyProperty and a Binding element as parameters, and so the setup for this would look something like the following:
myTextBlock.SetBinding(TextBlock.TextProperty, new Binding("BindingPath"){ StringFormat = "some format"});
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Thanks. That is exactly what I was looking for.
Hello dariush,
I am glad that I was able to assist you on this matter. Please let me know if you have any other questions or concerns on this issue.