groth
Topic Author
Posts: 5
Joined: 01 Apr 2022, 19:09

Noesis.Vector2 property naming doesn't match System.Windows.Vector

27 Jun 2023, 19:29

In System.Windows.Vector, the X and Y properties are defined as capitals ("X" and "Y"). But in the Noesis implementation of Vector2, the properties are defined as lowercase ("x" and "y"). Using the System.Windows.Vector in the XAML ends up throwing errors that there is no binding for the X property.

For example:
using System.Windows;

public class ControllerVisualizationContext
{
	...
	public ControllerInput ControllerInput { get; set; }
}

public class ControllerInput
{
	...
        // Ranged -1 to 1. Inactive = 0
        public Vector LStick { get; set; }
        ...
}
and in the Xaml:
<TextBlock x:Name="PreciseValue_L_Analog" Text="{Binding ControllerInput.LStick.X, StringFormat=\{0:F2\}}" />
Will throw the following errors:
Can't solve PropertyPath: Type 'Vector2' does not contain a property named 'X'
Binding failed: Path=ControllerInput.LStick.X, Source=Noesis.ControllerVisualizationContext.f1de4b00(''), Target=TextBlock('PreciseValue_L_Analog'), TargetProperty=TextBlock.Text
I can eliminate this if I modify the Vector2 reflection to add the capital accessors:
    NS_IMPLEMENT_INLINE_REFLECTION(Vector2, NoParent)
    {
        NsProp("x", &Vector2::x);
        NsProp("y", &Vector2::y);
        
	NsProp("X", &Vector2::x); // added
	NsProp("Y", &Vector2::y); // added
    }
I was curious if there was a specific reason the properties are different in their capitalization?
Are there any issues I'm unaware of in implementing this change?
Is there a better way to represent Vector2 (or Vector3) data that I'm not aware of?
Using System.Numerics.Vector2 has no properties defined in the C# side, so Blend doesn't like it.
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Noesis.Vector2 property naming doesn't match System.Windows.Vector

29 Jun 2023, 12:27

Your patch is safe. For historical reasons our math library is using lower case for properties. We have plans to improve this by hiding our math types for internal use (SIMD friendly, no reflection) and create new types in Drawing that will mimic WPF ones (there are already a few like Point, Rect, Color, Thickness...).

Please, feel free to file a ticket if you want to track this.

Who is online

Users browsing this forum: No registered users and 6 guests