Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent anti-aliasing in WPF 3.5

I am getting strange aliasing behaviour in a WPF app using FluidKit's ElementFlow control. We are using the control in an app at work for presenting content, and when the elements of the ElementFlow are tilted, the edges alias as per the following image: Aliased edges

In order to avoid the aliasing, we decided to get rid of the tilt angle, so I created a quick test app where I bound the tilt angle, item gaps, and popout distance to sliders so I could find out what looked best.

However, in the test app using the same settings, the edges are nicely anti-aliased: Anti-aliased edges

I am assuming there is some setting somewhere up the XAML hierarchy that is controlling this but I've tried setting SnapsToDevicePixels on various elements and styles, both at design time and run time (with bindings and tools like Snoop) to no avail.

The XAML for the ElementFlow is as follows:

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <Fluid:ElementFlow
            x:Name="ContentElementFlow"
            SelectedIndex="{Binding SelectedIndex}"
            Focusable="True"
            TiltAngle="15.95"
            ItemGap="0.722"
            FrontItemGap="0.052"
            PopoutDistance="1.631"
            HasReflection="False"
            Background="Transparent"
            CurrentView="{StaticResource CoverFlowView}"
            ElementWidth="175"
            ElementHeight="250"
            >
            <Fluid:ElementFlow.Camera>
                <PerspectiveCamera
                    FieldOfView="60"
                    Position="0,0,6"
                    LookDirection="0,0,-6"
                    UpDirection="0,1,0"
                    />
            </Fluid:ElementFlow.Camera>
        </Fluid:ElementFlow>
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

I've also tried both apps on two different machines (one running XP Pro, one XP Embedded, both have differing levels of dedicated graphics) and both demonstrate aliasing in one app and anti-aliasing in the other.

Does anyone know of any setting or XAML attribute that can be used to control this?

like image 804
jeffora Avatar asked Aug 09 '10 23:08

jeffora


3 Answers

If I remember correctly there is a bug in WPF 3.5 regarding aliasing in this scenario, I can't for the life of me find the relevant information, but from what I remember it was a Direct X flag that was not being set correctly by WPF.

I remember finding that if you wrap the offending element in certain types of parent elements it seemed to fix the problem. For instance I think wrapping the offending element in an empty border fixes the problem? Again, I can't for the life of me find the information again, but if I find it I will update my answer.

I assume the differences you are seeing between applications are related to this. In the app that show aliasing are the items in the ItemTemplate wrapped in some sort of parent element (where as the test app they are not)? Or vice-a-versa?

Sorry I can't be of more help, still looking for the information but my Google powers seem weak today.

UPDATE: Ok I found what I was thinking of.

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7382637b-b4bc-4a46-8bed-f36250a65385/

This was related to effects so maybe this isn't the same thing you are seeing but worth a shot.

like image 64
Brad Cunningham Avatar answered Sep 20 '22 12:09

Brad Cunningham


One thing to consider is the location of the ElementFlow control. If it's arrange rect isn't on a whole pixel, that may throw off everything. SnapToDevicePixels will not help with the arrange rect.

This generally happens when you use TextBlocks, since their heights/widths are generally not whole numbers.

In .NET 4, there is a new FrameworkElement.UseLayoutRounding that fixes this issue.

like image 23
CodeNaked Avatar answered Sep 18 '22 12:09

CodeNaked


This a common problem of WPF 3D. FluidKit's ElementFlow uses WPF 3D. The items in the control are acutal 3D objects (Viewport3D, ContainerUIElement3D). Subpixel rendering issues, LayoutRounding and SnapToDevicePixels do not apply to 3D content. WPF reverts to aliased Viewport3D content when the performance is not right. So most likeley your problematic app is consuming too much resources (CPU, GPU, memory). I have made the experience that this happens much more freqeuntly under windows XP than under Vista/Windows 7. For Windows XP it helps a bit to set the antialiasing registry key. Other than that and improving the perfomance of your app, there is not much more you can do about it.

like image 45
bitbonk Avatar answered Sep 18 '22 12:09

bitbonk