tags:

views:

402

answers:

4

Well the title says it all im using .net sp1 on both computers..

My layout is like this window that has no toolbar and is set to maximize so it fits the hole screen.

Under that i have a Viewbox set to use Stretch: Uniform, and under that i have my LayoutRoot.

This way i hoped to get the same layout on all computers but it seems it doesn't render exactly the same on xp some items are a bit smaller.. and the layout doesn't look that great...

I have tryed to change my resoulution on my windows 7 computer to the same as the XP computer and it keeps the layout like supposed to..

And both computers use 96 DPI.

Windows XP

Windows 7

+1  A: 

My experience:

I'm not sure if it is the issue, I noticed Windows 7 uses hardware acceleration to draw the WPF application. Windows XP doesn't.

You can check if this is the case by using something like this:

public partial class App
{
    public static int Tier { get { return RenderCapability.Tier >> 16; } }

    static App()
    {
        Console.Out.WriteLine("Render Tier: {0}", Tier);
    }
}

Your rendering tier should return 2 if it used full hardware accelerated drawing. 0 = software, 1 = something in the middle if guess

Rick
WPF uses hardware acceleration on all supported operating systems. XP is more susceptible to video tearing, something the DWM (Vista, 7) helps to fix.
Jeremiah Morrill
+2  A: 

Different versions of Windows have different default fonts (also different versions of the same fonts) and different font rendering engines - as a result the text size is different between systems.

You can try to set the font to the same font and see how it works, maybe try several fonts to check where the difference is smallest.

Nir
You can also include the font to your application. Expression Blend creates the Fonts folder for this purpose (via Tools > Font Manager...)
Rick
+1  A: 

The default fonts are different

Make a WPF button

<Button x:Name="button" Width="100" Height="25" Content="Button" Click="Button_Click"/>

and code behind:

private void Button_Click(object sender, RoutedEventArgs e)
{
    string msg = string.Format("Number of fonts: {1}{0}Font Family: {2}{0}Font Size: {3}",
        Environment.NewLine,
        button.FontFamily.FamilyNames.Values.Count.ToString(),
        button.FontFamily.FamilyNames.Values.First().ToString(),
        button.FontSize.ToString());

    MessageBox.Show(msg);
}

Run this on each operating system and you will see that the default fonts for XP and Windows7 are different.

Default font for XP is “Tahoma” size 11

Default font for Windows 7 is “Segoe UI” size 12

Paul
+1  A: 

Took me about 3 hours to finally figure this out - after much detective work, but now it is pixel perfect !

Appears that WPF on XP and WPF on Windows 7 not only have different default font faces as well as a default font sizes.

  • I had a problem where fonts were rendering differentl on XP from how they were on Windows 7. It was quite critical since the final output was the printer and they needed to be identical. It appeared initially that the problem was a difference in line spacing.
  • Yes - I had the same exact font installed on XP as I was using on Windows 7
  • Yes - I tried a very generic font (Arial) and still had the same problems.
  • Yes - Same DPI on both machines.
  • Yes - Same result whether in a VM (XP Mode) or on a real XP machine.

Eventually I discovered that the fonts where I was specifying an explicit size looked identical on XP, and only the ones where I didn't specify an explicit size were they different.

So here's how I fixed it in my MainWindow.xaml - with a ContentControl to set a default size:

<Grid x:Name="LayoutRoot" Background="#FFDEDEDE" UseLayoutRounding="True">

    <ContentControl FontFamily="Segoe UI" FontSize="12">

         ... window contents ...

    </ContentControl>
</Grid>

Note: If you're using Blend you may need to enter FontSize="12" by hand. If you select it from the properties designer it will delete it because it thinks 12 is already the default!

Like I said my destination was the printer - so i had to do the same for the control being printed.

Now if anyone knows where else I can set this default font size please let me know - but now I have pixel perfect rendering on XP and Windows 7, and they differ only by the cleartype anti-aliasing differences.

Note: UseLayoutRounding is not part of my solution - but I always use it on my root control also.

Simon_Weaver