helix-toolkit: Torus class TubeDiameter Property binding fails in WPF UserControl

I created a user control containing a TorusVisual3D object inside HelixViewport3D. Everything works. But when I bind to the TubeDimaterProperty in XAML or in code my program crashes. I am not very advanced in WPF. I was not able to pinpoint the exact issue. Since other properties work well and binding in code also fails for the TubeDimaterProperty, I am inclined to think the problem is with the TubeDiameter property. I looked into the source code, as I indicated I am not very advanced in WPF.

<UserControl x:Class="Torus2020A.TorusUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hx="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" xmlns:local="clr-namespace:Torus2020A" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> <Grid> <DockPanel> <hx:HelixViewport3D x:Name="UCTorusView" ModelUpDirection="0,1,0" ZoomExtentsWhenLoaded="True" ShowCoordinateSystem="True" PanGesture="LeftClick"> <hx:TorusVisual3D x:Name="UCTorus" TorusDiameter="{Binding Path=UCTorusDiameter, RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=1}}" TubeDiameter="{Binding Path=UCTubeDiameter, RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=1}}" ThetaDiv="{Binding Path=UCThetaDiv, RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=1}}" PhiDiv="{Binding Path=UCPhiDiv, RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=1}}" /> </hx:HelixViewport3D> </DockPanel> </Grid> </UserControl>

This is the failing XAML (removing TubeDiameter or assigning a value to it works):

This is the binding in Code:

// var b = new Binding("UCTubeDiameter"); // b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(UserControl), 1); // BindingOperations.SetBinding(UCTorus, TorusVisual3D.TubeDiameterProperty, b);

I tried Visual Studio 2017 with Framework Version 4.6 and 2019 with 4.7. The results were the same. Thank you for a wonderful contribution. Please let me know if you need the whole solution.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Attached please find the offending code (Solution) created with Visual Studio 2017. If you change the TubeDiameter entry in the TorusUserControl.XAML to TubeDiameter=“1”, it works. Thank you very much for torus20.zip your attention and time.