This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, We have a requirement where diagram nodes have to be snapped within snaplines. We have a custom snapline drawing which used to work perfectly with version 2.0 while panning/scrolling. After the upgrade from WPF Diagram 2.0 to 4.0 , during panning the snaplines don't seem to be re-drawing themselves correctly. I have attached a sample project with sample diagram nodes and the snapline drawing class, and if you run the sample project after referencing 4.0 dlls, on panning you can see that the movement of the diagram nodes and the snaplines are not in sync. If you observe carefully, on very slight movement(panning) only the diagram nodes would move but not the snaplines. This was not the case before the upgrade. Could someone help me figure out how to get around this problem and keep the snaplines and the diagram nodes in sync? Thank you. Regards, Nishanth |
|
|
Hi Nishanth, Thanks for the repro project and sorry for the trouble here. The issue is caused by rendering a line outside the viewport which in version 4.0 now causes the snapline drawing to shift/align in a way to render those out-of-bounds lines within the viewport. This easily causes the grid lines to be out of sync with the diagram. The reason this behaviour has changed was to improve the pixel snapping of gridlines, but causes this unwanted side-effect Fortunately, this is easy to solve. In your CustomSnapLineDrawing, each iteration of your loops will draw 2 vertical lines, and 2 horizontal lines. The first line that gets drawn is always going to be within the viewport due to the way that GetGuidelines is implemented. To solve the issue, put a check around the rendering of the second line of each loop. The check for the Y lines will be:
And the X lines will be:
Remember, this is just for the second DrawLine of each loop, as the first DrawLine in each loop is fine. Let me know if you have further questions about this. -Jason Fauchelle |
|
|
Hi Jason, Thank you, your suggestion has solved the 'sync' issue. But even after that fix, I happen to notice another side effect. If you apply the 'sync' issue fix and also give a certain height to the diagram surface in my previous repro project( so that the ScrollViewer's scrollbar becomes visible. I am not using the DiagramSurface's ScrollBar), and on scrolling to the very top or very bottom of my application, you will notice that the last horizontal snaplines disappear. I have attached a screenshot below. Unfortunately with the exact setup in my actual application, all of horizontal snaplines disappear not just the last one. Any inputs on this? Thanks. -Nishanth |
|
|
Hi Nishanth, The missing line in the image is one of the "second lines" to be drawn in the horizontal lines loop. The "first line" that corresponds to the missing "second line" never exists because it is below the bottom of the viewport and so the while loop in GetGuidelines stops before drawing it, and thus the line above it which is in the viewport will also not be drawn. Note that the vertical lines suffer the same problem on the right hand edge of the diagram. One way to fix this could be to pass bounds.Bottom + ObjectHeight as the endValue of GetGuidelines, that way, lines can continue being produced a little bit below the viewport which will allow that missing line to be rendered. This may require you to add additional checks to not actually render lines below or to the right of the viewport. (I haven't tried this so you'll need to check if this is necessary). Another way to fix this which may be less confusing for the future could be for the GetGuidelines method to return both the main lines, and the spacing lines. That way, they are created consistently and the logic used to stop looping will consider both lines. The draw loops would then only be rendering a single line in each iteration as the GetGuidelines method would be providing everything. Hope that helps, let me know if you have further questions. I have not been able to reproduce all horizontal lines missing. I have however seen that the nested scroll viewers can produce weird blurring of the grid lines. I recommend removing the out scroll viewer if/when possible as the DiagramSurface has not been designed to be used in this way. -Jason Fauchelle |
|
|
Hi Jason, I have tried your first approach but with no success. I couldn't completely understand the alternative solution which involved changes to the GetGuidelines method. Right now it is not possible for us to remove the outer scroll viewer as there are other functionalities in our application which depend on the outer scroll viewer. Could you provide any other alternative solution to the problem or a repro solution of your second suggestion of tweaking the GetGuidelines method? Thanks you. -Nishanth |
|
|
Hi Nishanth, Regarding the first solution, could you please provide a repro project demonstrating the problems you've seen and I'll have a look at solving them. -Jason Fauchelle |
|
|
Hi Jason, I apologize for not being completely clear. The first solution did actually work for on my repro project i sent you earlier.But it didn't work in my actual application, since my horizontal snaplines were disappearing completely. They disappear when I scroll to the very top or very bottom of the diagram surface. When i click the scroll up/scroll button once they all come back. I was able to reproduce this in a repro project by giving a sufficiently high value to the "Height" property of the Diagram surface. I have given a value of 9875 as height of diagram surface in the repro project to see horizontal lines disappearing.This value might vary based on the screen size you are using. I had to bind the height property of DiagramSurface to a property in my view model because of the issue I had earlier which was resolved here : http://www.mindscapehq.com/forums/thread/3662036. I look forward to hearing back from you. Thank you -Nishanth |
|
|
Hi Nishanth, Thanks, I understand now, and had reproduced something similar with your repro app before. Sometimes the vertical lines become stretched, which is noticeable due to the dash array. Sometimes the horizontal lines become blurred. Sometimes the left half of the horizontal lines are fine, but the right half is either blurred or missing. Sometimes the horizontal lines disappear altogether. Usually when the horizontal lines are partially visible, they are in the wrong place. Certainly seems that the drawing is being stretched vertically in some way, but I honestly am not sure why. The grid drawing only gets rendered once in this scenario, and so the exact same visual element that is displayed incorrectly when the scrollbar is at the very top or bottom, is the exact same visual element that is being rendered correctly when the scroll bar is in the middle. Looks like a bug or a limitation with the .NET Drawing used in this set up. Unfortunately my second suggestions is going to suffer from the same issue as this is something we can not control. One thing you may be able to attempt is to force your outer scroll bar to never be allowed to quite reach the top or bottom. Other than that, I'm out of ideas. If you are planning to remove the outer scroll bar at some stage in the future, perhaps put this issue on hold for now - as removing the outer scroll bar does resolve the issue. Sorry I couldn't provide an immediate solution here. Let me know if you have further questions. -Jason Fauchelle |
|