WPF Framework Canvas Automatic Scaling based on largest coordinate in list
Hi.
First of all, thank you for reading!
I have a MVVM WPF application and having some trouble with the Canvas and how to draw shapes that are automatically scaled to the canvas size.
Let's say I have a model Y that contains a list of X. X has a location and my goal is to display all X's in a fixed size canvas using circles.
The location of each X can vary wildly so for every list of X that gets selected I need to use the largest coordinate of the furthest X in that list to scale it so all the X's show up properly on the canvas, the furthest one should be located 10% away from the canvas' border. Assuming (0, 0) is the middle of my canvas the calculation for this should be
I am using the CalcBinding nuget so I can do calculations in my binding, like so:
The problem: I can't seem to use the LargestCoordinate property from the ancestor (which is Y) in my calculation for each X
I can get that property in xaml correctly using:
but cannot use this method in my full calculation:
it just gives a whole lot of XAML binding errors like this one:
System.Windows.Data Warning: 40 : BindingExpression path error: 'FindAncestor' property not found on 'object' ''Planet' (HashCode=19050756)'. BindingExpression:Path=FindAncestor; DataItem='Planet' (HashCode=19050756); target element is 'TranslateTransform' (HashCode=48896832); target property is 'X' (type 'Double')Is there any way I can use the LargestCoordinate property from Y in my calculation for each X so I can scale the locations properly?
5 Replies
relevant code:
If there is a better way without Canvas or using a different method, feel free to chime in.
I have also tried ViewBox but haven't gotten that one to work as well as the solution I posted above.
Almost solved the issue myself, just need to figure out this next problem
I don't know why this following code can't get find the property RadiusX on the EllipseGeometry https://i.imgur.com/izux1tM.png
https://i.imgur.com/7Lr98Na.png it used to be able to find the old Ellipse element and get me the width and height, but it can't with EllipseGeometry?
I fully managed to get it working using this code