question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Torus class TubeDiameter Property binding fails in WPF UserControl

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
ikonukcommented, Oct 8, 2020

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.

0reactions
chrkoncommented, Oct 11, 2020

@holance I have made another test for this issue. I just have removed the exception from the AddTorus method.

And now the original code from I. Konuk (without defining a default value for the tube diameter) is running.

These are my changes in the MeshBuilder class (Line 3024):

            else if (tubeDiameter <= 0.0)
                Debug.WriteLine("Torus must have a Tube Diameter bigger than 0");
                //throw new HelixToolkitException("Torus must have a Tube Diameter bigger than 0");

I saw 2 lines in the debug output. So the “tubeDiamater == 0.0” case came two times, but after this everything was OK.

I would suggest to remove the exception and the debug code and just do nothing in case of tube diameter == 0. If the diameter is zero, nothing will be drawn.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HelixToolkit: binding to TubeDiameter Property of Torus ...
It turns out that this is a small bug in HelixToolkit. The workaround can be seen in the following: Torus class TubeDiameter Property ......
Read more >
UserControl Class (System.Windows.Controls)
Gets a collection of CommandBinding objects associated with this element. A CommandBinding enables command handling for this element, and declares the linkage ...
Read more >
A Simple Pattern for Creating Re-useable UserControls in ...
This blog post provides step-by-step instructions for creating a user control, which exposes bindable properties, in WPF and Silverlight.
Read more >
33-User Controls | Part 3 | Data Binding - YouTube
Welcome to WPF Tutorials | User Controls in WPF | Databinding in WPF In this part of User Controls ... #How to Data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found