It seems that many people are trying to turn OFF anti-aliasing in WPF, but I seem to have the opposite problem. I am drawing shapes in WPF, and the edges are all aliased and ugly. The worst part is that when I use a ScaleTransform to zoom out such that a shape is less than one pixel tall/wide, it disappears entirely. How can I make them smooth and pretty?
Currently, I am drawing Rectangles and Ellipses and placing them in grids and StackPanels.
After a lot of googling, I found out how to get my images to anti-alias by using the following line in my window's constructor: RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant);
However, this only affects my Images and not my Shapes.
I have what I think is the same problem. Setting SnapsToDevicePixels to false works for me:
<Ellipse SnapsToDevicePixels="False" />
You can set the EdgeMode the same way you set BitmapScalingMode
RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified);
But Anti-Aliasing is set as default so you should not need to change it, but give it a go :)
Also setting SnapsToDevicePixels = true; on your window may help with the shapes.
Related
I'm having a problem with auto sizing all of the controls on my WPF. I'm able to get them too stay on the side of the screen where I want them, the only problem is that, when I have the window the same size as the editor, it looks perfect, however, when I change too full screen (Has too be full screen), it centers everything rather then stretching too fit across the entire window.
Any idea how I could go about fixing this? I have provided a few photos.
After doing a lot of research, I found putting it in a panel, and then making the panel Anchor too none and then setting the Alignment too none, it fixed the windowed version but not full screen version. Any help would be great.
I'm setting the window too full screen with this.WindowState = FormWindowState.Maximized; if that makes any difference at all?
The grid should help you with that, just define columnas and rows. Then put the controls inside the rows and change the alignment (vertical and horizontal) to stretch and you are done.
You will have a problem with the text size, that need tl be managed in code behind or in your viewmodel
If you want a control to span on mĂșltiple rows or multiple columns use the grid.rowspan and grid. Columnspan properties.
Sorry for the bad formatting, im on the phone
Hi I'm hoping someone can help point me in the right direction to how i might go about solving this issue.
I have a blank image (white) which is 3000x1500 which acts a a canvas, i then have an image which again could be any size and any orientation. What i need to do is scale this image to fit inside the blank white canvas as best as possible and also center it. I would expect to see white gaps at the top or bottom of the final image if the image could not be scaled to fix the exact canvas.
Can anyone suggest what i should research, how i would go about drawing an image inside another in C# WPF and anything that may already exist that i could use to achieve this.
I forgot to mention that this would need to output to a bitmap so it could be saved to disk
All you need to do is to put an Image control into an appropriately sized Grid with white background, and set its Stretch property to Uniform. No Viewbox required.
<Grid Width="3000" Height="1500" Background="White">
<Image Source="<path to image file>" Stretch="Uniform"/>
</Grid>
Look up ViewBox. A ViewBox automatically scales its single child element based off of the stretch parameter.
I have a problem that all of my LinesVisual3D are not visible, when placed after an object with semi-transparent material (lowered alpha channel). All other 3D objects are visible when placed behind, but the lines are not. What is more, when the lines partially intersect with the object, only the part that is not intersecting is visible.
Is it possible to make these lines visible?
I believe this might be an effect of how WPF 3D handles opacity. I've had similar issues with other Visual3Ds.
Have a look at Transparency in WPF 3D.
Basically you have to add opaque and transparent objects in the correct order. Try adding the opaque objects last. I.e. add the LinesVisual3D you're having issues with, then add the things with lower opacity.
Disclamer: I have not tried your scenario with specifically LinesVisual3D, so it might be that there is a bug in Helix regarding that specific visual.
I am trying to figure out how to add a full shadow around a borderless form, using WinForms. I am looking at adding a shadow around all four sides of the form.
I have tried using the DropShadow class, although it only adds the shadow to the bottom and right side corners.
I have seen this question asked many times before in my searches but nothing I cam upon had an answer for all four sides.
I am using both C# and VB.net languages in my solution so any help regarding either language would be a big help.
You are going to have to manually draw this. I have done something similar before with a splash screen, I think. You need to decide the offset of the shadow from the client area of the form and either create a container (easier layout wise) to host its constituent controls or redefine its client rectangle programmatically if you need dynamic shadow size, and then draw your border. If memory serves, you will get the best results using alpha blending + lineargradientbrush to fade the shadow transparency out to the edges.
I'm looking to teach myself better methods of doing things in WPF that I would normally do manually.
In this case, I have a ViewBox with an image in it. I also have a button that uses a DoubleAnimation to rotate the image 90 to the right.
This animation works fine, but obviously because it's square as it turns, the image does a "best fit" to the ViewBox which makes the rotation look quite bad, as it gets larger and smaller as its longest edge shrinks or grows to fit to that particular rotation angle.
I am looking for any advice on the best way to handle this using appropriate WPF methods. Obviously I could do all the calculations manually, but I would be more interested in finding a way to use the controls and methods built into the .NET architecture.
Thanks for your help.
If you only have an Image in your ViewBox, drop the view box. An image is already capable of stretching correctly with the Stretch attribute set to Uniform.
In any case, use a RenderTransform instead of a LayoutTransform, to avoid recalculating the position of the controls when the images rotates. RenderTransform will rotate the object after all position calculations are done so you'll be fine. Just add a margin around the image if you find that it pass over some control while rotating.