SnapsToDevicePixels seems to not work in StackPanel - wpf

I have more expanders in StackPanel (Orientation=Vertical). When I expand one, the others below the expanded one seem to be blured. Like it would SnapsToDevicePixels=False.
I think the problem could be in StackPanel because it doesn't support UseLayoutRounding in .NET 3.5 (which I use) yet. Is that possible or the problem could be elsewhere?
I put SnapsToDevicePixels="True" almost everywhere I could, but nothing changed.
(Font has size 12 so it couldn't be [1]: WPF Blurry fonts issue- Solutions)

Try set UseLayoutRounding property it should adjust layout to use position rounded to integer.
http://www.switchonthecode.com/tutorials/wpfs-most-important-property-uselayoutrounding

I solved a similar problem with RenderOptions.EdgeMode="Aliased"

Related

image gallery with scrollviewer - wrap panel does not respect boundaries of scroll viewer

I'm trying to create a gallery-style layout with a ScrollViewer and a WrapPanel in WPF, but the WrapPanel is extending beyond the boundaries of the ScrollViewer. I've tried setting the HorizontalAlignment and VerticalAlignment properties of the WrapPanel to "Left" and "Top" respectively, but it still doesn't stay within the boundaries of the ScrollViewer.
I've also tried setting the height of the WrapPanel to specific values and set the MaxHeight properties of the WrapPanel to limit the size, but it still doesn't stay within the boundaries of the ScrollViewer, and is no longer scrollable. I've also tried wrapping the WrapPanel inside a Grid and set the height of the Grid to the size I want and set the ClipToBounds property of the Grid as "True", but it still doesn't work.
I'm not sure what else I can do to keep the WrapPanel within the boundaries of the ScrollViewer. Can anyone help me figure out how to contain the WrapPanel within the ScrollViewer?
This is my xaml code:
<ScrollViewer Grid.Row="0">
<WrapPanel x:Name="Preview_WrapPanel"></WrapPanel>
</ScrollViewer>
and this is my result in my app, in the beginning, the distance from top is correct but the bottom not. I scrolled a little up to show that the height is not respected in the top region as well:
the width is respected, but i think only because this is the application width.
The thick red border is the area, which the scrollviewer occupies. The wrappanel should be contained inside, kind of like a window, where you can only see whats behind the window and not the trees behind the wall.
the wrappanel gets filled with WebView2 Media, each image around 200x200px:
WebView2 media = new WebView2();
media.Source = new Uri(nftFile.FullName);
media.Width = 200;
media.Height = 200;
this.Preview_WrapPanel.Children.Add(media);
I use Webview2 because the content could pretty much be anything, image, video, pdf, whatever. Also it supports webp
For now though, im only adding images.
There was a known bug with webview2 and it seems it has not been fixed.
Basically, renders on top so cannot be clipped.
https://github.com/MicrosoftEdge/WebView2Feedback/issues/2579
https://github.com/MicrosoftEdge/WebView2Feedback/issues/286
You need a different plan.
Maybe ensure it doesn't matter when they don't clip.
Maybe use images.
Or hope it gets fixed soon.
Andy was correct, this is a known issue. Microsoft knows about it since .net framework Times (>10 years) but refuses to fix the issue so far.
I solved the issue by Installing the Nuget Package CefSharp which uses the chromium engine as well.
What a pitty.

WPF Animation on scrollviewer children clipped by scrollviewer

Hey folks, I'm hoping I have a fairly simple problem that can be fixed easily as it seems like I'm just missing something basic from the WPF world. I have a scrollviewer wrapping a stackpanel which contains several images, these images have animations to increasing in size when the mouse passes over them. All works fine without the scrollviewer, now I've added the scrollviewer, the animation works but only inside the scrollviewer; the increasing size isn't being allowed to overlap the scrollviewer.
Is there a way to fix this?
Thanks,
Becky
It's the way ScrollViewer works. Basically it always clips to bounds even if you set ClipToBounds="False" on it.
To make it work and continue using ScrollViewer you'll have to animate images on top of it, not inside.

Any hints for dealing with snap to device pixels in WPF

Many controls in WPF has this snap to device pixels (as explained on MSDN). I just often find myself forgetting to set it and then later discover that something sometimes looks odd because of this.
What do people use to deal with this issue?
SnapsToDevicePixels property is inherited through the element tree.
I always set SnapsToDevicePixels="True" on each Window, and all the children inherit the value.
(But I don't have any suggestion for how to remember to set it on each Window.)
SnapsToDevicePixels="True" does not trickle down into an OxyPlot grid, however...
Some of the grid lines show up double.
and OxyPlot PlotView's SnapToDevicePixels does not help either.

Why is DataGrid "Auto" width so huge all the sudden?

I have been working on an app with a datagrid from the wpf toolkit and the width was not specified in the xaml (default to auto), and it was working fine. It would extend the window width as I resized the window. However, all the sudden the "auto" width is massive and I don't know why. When I pull the xaml file up in blend it shows auto width is 50002 pixels. I barely touched anything else in my xaml since it happened. Anyone know why it is doing this and where that number came from? Thanks
The most common cause for this that I've seen is when the control is inside a StackPanel with Orientation=Horizontal. StackPanels don't constrain their controls in the stacking direction so if nothing else constrains the control it grows to some maximum size.
If this is the issue try replacing your StackPanel with an equivalent DockPanel or Grid.
If you were doing any manual resizing using the Visual Studio IDE then perhaps this could have happened or you could have accidently typed in the wrong size of 50002. Removing the widths and setting to auto should fix the issue.

Silverlight Border - Am I stupid?

sorry, I did not find something useful when searching google. Very basic question, mainly "Am I stupid". I know StackPanel gives its child elements full space, but why does the "Auto" property relate to the PARENT element in case of a border. I mean perhaps I am doing something wrong, but this behaviour is definitly not what I intended:
Pic1 http://img6.imageshack.us/img6/171/20090805002723.jpg
Ok, after some thinking I found a way, which looks like this:
Seriously http://img18.imageshack.us/img18/3173/20090805003045.jpg
But really, this way? I mean a "minimal sized control" with a textbox (which width I want to define) and a border around it, and I need this kind of tree? If anyone has a better way, please tell me...
Chris
PS: And that while I am writing about the nice UI composition for Silverlight, and wanted to give a simple example.. I just say: Legendary!
Definitely not stupid. This can be very confusing. I find it helps when thinking about layout in WPF/Silverlight to think top down from the root of the control hierarchy instead of bottom up.
It becomes obvious when you think about the stack panel's job. It stacks up its child elements and sets their widths to its width. It is therefore overriding your border's width of Auto. The Canvas you later wrapped around it does not try to rearrange its children at all, and it does not override their widths, so while its width is the width of the stack panel, the Auto on your border is now working (sized to its content, the TextBox).
Clear as mud?
Here is an article with more detail:
http://msdn.microsoft.com/en-us/library/ms745058.aspx
And I highly recommend the WPF book by Chris Sells & Ian Griffiths to get up to speed on the intricacies of WPF/Silverlight layout.
Canvas sould be avoided unless it really makes sense for what you're trying to do. For example, Canvas normally makes sense for a game, or something where you want to drag elements around. Here it's just getting in your way.
Reasons not to use Canvas:
http://blogs.msdn.com/devdave/archive/2008/05/21/why-i-don-t-like-canvas.aspx
An easy way is to get rid of the Stackpanel and just use the VerticalAlignment and HorizontalAlignment to keep it at the top left. Then just set the Border Width and leave the Height alone.
<Grid x:Name="LayoutRoot">
<Border Width="150" BorderBrush="Blue" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBox Text="I'm Serious" Background="LightBlue" />
</Border>
</Grid>

Resources