Here is where I set the line style of the trackball line just as recommended in Telerik's article. The only difference is that did not set the visiblity to a hard-coded value. Instead I bound it to a dependency property on my control using my well-tested bool-to-visiblity converter
<
tk:RadCartesianChart
x:Name
=
"Chart"
>
<
tk:RadCartesianChart.TrackBallLineStyle
>
<
Style
TargetType
=
"Polyline"
>
<
Setter
Property
=
"Visibility"
Value
=
"{Binding ElementName=Root, Path=ShowInfo, Converter={StaticResource CvtBoolToVis}}"
/>
</
Style
>
</
tk:RadCartesianChart.TrackBallLineStyle
>
Unfortunately that Visiblity binding in the line style is only evaluated the very first time the chart displays. AFter that, it doesn't matter if I change that boolean "ShowInfo" property or not. The binding never gets re-evaluated.
I've put a breakpoint in my converter to make sure it gets evaluated correctly the first time.
I've put a breakpoint in the dependency property to verify that it truly does change. And I even bind properties of the TrackBallBehavior to that very same ShowInfo property and their bindings DO get re-evaluated when it changes so I know that works.
<
tk:ChartTrackBallBehavior
ShowIntersectionPoints
=
"{Binding ElementName=Root, Path=ShowInfo}"
ShowTrackInfo
=
"{Binding ElementName=Root, Path=ShowInfo}"
SnapMode
=
"ClosestPoint"
/>
So how can I dynamically show/hide the trackball line?
6 Answers, 1 is accepted
Hi Joe,
Thank you for the provided code.
I was able to observe this behavior. You are right that binding the Visibility property will not work. Not sure why this is happening. After a few tries on my side, I couldn't make it work through binding the Visibility property. Instead, I think I found an easy way. You can use DataTriggers and bind the Stroke property instead. When you want to hide the line, you can set this property to Transparent.
<telerik:RadCartesianChart x:Name="ChartView">
<telerik:RadCartesianChart.TrackBallLineStyle>
<Style TargetType="Polyline">
<Setter Property="StrokeThickness" Value="2" />
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.ShowInfo,
RelativeSource={RelativeSource AncestorType=Window}}"
Value="True">
<Setter Property="Stroke" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding DataContext.ShowInfo,
RelativeSource={RelativeSource AncestorType=Window}}"
Value="false">
<Setter Property="Stroke" Value="Transparent"/>
</DataTrigger>
</Style.Triggers>
</Style>
</telerik:RadCartesianChart.TrackBallLineStyle>
<telerik:RadCartesianChart.Behaviors>
<telerik:ChartTrackBallBehavior/>
</telerik:RadCartesianChart.Behaviors>
. . . . .
I hope this approach will work for you.
Regards,
Dinko
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).
![](/forums/images/avatarimages/default.gif)
![](/forums/images/avatarimages/default.gif)
Sorry to "unmark" this as fixed but I didn't realize at the time: This fixed caused another problem so I have had to remove it.
On the same chart I have CartesianPlotBandAnnotations. They are colored rectangles. In their styles, I have EventSetters for mouse events --- because I let the user select and drag them around the profile. This has all worked very well for a long time now.
Unfortunately, as soon as I add that TrackBallLineStyle that you showed me, my mouse handlers no longer get called on mouse events for these annotations. Not at all.
What is even odder is that my mouse event handlers for the entire chart still *do* get called. It's like the annotations are suddenly not hit-detectable or something. But I can still see them plainly there.
If I comment out the Trackball line style, suddenly all the mouse handlers for the annotations get called again.
If you think it will help I can try to create a sample application to show this. It will take me a while (this is a pretty busy display) but it will show you what I mean.
For now I have to simply remove that trackball line style and let the line show all the time if I want my regions to be draggable
Hello Joe,
Thank you for the details.
It will be great if you can isolate this in a standalone project. This way, I can more carefully examine this behavior. Still, I have tried to reproduce it on my side, but mouse events are called on the annotations. I have tested the MouseEnter and PreviewMouseDown, and both events are called. The only thing which I changed is to set the IsHitTestVisible property of the CartesianPlotBandAnnotation to true. Can you list which events stop working in your application?
Regards,
Dinko
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products, quickly just got a fresh new look + new and improved content, including a brand new Blazor course! Check it out at https://learn.telerik.com/.
![](/forums/images/avatarimages/default.gif)
Instead of simply defining a behavior in XAML and then binding its properties according to the settings of a checkbox, instead what I did was add/remove the behavior in code-behind whenever the "IsChecked" properties of the checkbox changed By using that approach, I was able to completely remove all traces of the track ball behavior when it was not wanted.
It would be nice if there were a property in the ChartTrackBallBehavior that I could bind to in order completely disable it. But this works for me.
Hello Joe,
I'm glad to hear that you've managed to find a suitable solution for your scenario. If you believe that exposing an additional property to control the visibility of the trackball would be valuable to other clients as well, you can open a new feature request in our feedback portal.
Regards,
Dilyan Traykov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.