Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
100
Custom Binding for Tooltips Only in CodeBehind
posted

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?

Parents
  • 34430
    Verified Answer
    Offline posted

    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,
    Andrew
    Associate Developer

    XamDataChartTooltipsCodeBehindCase.zip
Reply Children
No Data