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
Setting tooltip for programmatically added series

I am programmatically adding series to my XamDataChart; these data come from the server and hence I can't put them in xaml since I wouldn't know how many series I will get back.

When I tried to add tooltip using a tooltip template I kept getting: 'ToolTip' cannot have a logical or visual parent. Same problem when I tried to wrap this in a markertemplate instead.

Other than this the series display fine. Can you advise?

My code:



























        private void AddSpreads(SomeDataCollection panelVMs)
            var toolTipTemplate = SpreadChart.Resources["ToolTipTemplate"] as DataTemplate;
            for (int i = 0; i < panelVMs.Count; i++)
                RolledATMVolPanelViewModel panelVM = panelVMs[i];
                string pair = panelVM.CcyPair;

                // add to spreads chart
                var series = new ScatterLineSeries
                                     Title = pair,
                                     MarkerType = MarkerType.Circle,
                                     Brush = CommonSettings.Colours[i % CommonSettings.Colours.Length],
                                     XAxis = XAxis,
                                     YAxis = YAxis,
                                     XMemberPath = "DaysToMaturity",
                                     YMemberPath = "Spread",
                series.MarkerBrush = series.MarkerOutline = series.Brush;
                if (toolTipTemplate != null)
                    var toolTip = new ToolTip();
                    toolTip.ContentTemplate = toolTipTemplate;
                    series.ToolTip = toolTip;

                var spreads = new List<SpreadItem>();
//... here I populate spreads with data from teh view model

                series.ItemsSource = spreads;

My xaml:

              <Controls:XamDock Margin="0">
                <Charts:XamDataChart Controls:XamDock.Edge="Central" Margin="3" Legend="{Binding ElementName=Legend}"
                                     VerticalZoomable="True" VerticalZoombarVisibility="Collapsed" Background="Transparent"
                                     HorizontalZoomable="True" HorizontalZoombarVisibility="Collapsed" Name="SpreadChart">
                    <DataTemplate x:Key="ToolTipTemplate">
                      <StackPanel Orientation="Vertical">
                          <TextBlock FontWeight="Bold" Text="{Binding Series.Title}"/>
                          <TextBlock FontWeight="Bold" Text="Mty: "/>
                          <TextBlock Text="{Binding Item.DaysToMaturity}"/>
                          <TextBlock FontWeight="Bold" Text="Spread: "/>
                          <TextBlock Text="{Binding Item.Spread, StringFormat=0.00%}"/>
                    <Charts:NumericXAxis x:Name="XAxis" Label="{}{:0}" MajorStroke="Transparent" MinorStroke="Transparent"
                                         IsLogarithmic="True" LogarithmBase="10" >
                        <Charts:AxisLabelSettings Location="OutsideBottom" Extent="35" />

                    <Charts:NumericYAxis x:Name="YAxis" Label="{}{:0.00%}" >
                      <Charts:NumericYAxis.LabelSettings >
                        <Charts:AxisLabelSettings Location="OutsideLeft" Extent="55" />

                <Charts:Legend Name="Legend" Controls:XamDock.Edge="InsideTop" Controls:XamDock.VerticalDockAlignment="Top"