Warning: Undefined array key "oxygen-cache-1409" in /var/www/wordpress_jb/wp-content/plugins/jetpack/class.jetpack.php on line 5759

Warning: Undefined array key "oxygen-cache-1414" in /var/www/wordpress_jb/wp-content/plugins/jetpack/class.jetpack.php on line 5759

Warning: Undefined array key "oxygen-universal-styles" in /var/www/wordpress_jb/wp-content/plugins/jetpack/class.jetpack.php on line 5759

Improper Rendering of XAML?

Posted on September 13, 2009

I’m working on a project right now and have noticed that XAML seems to be incorrectly rendered in the Visual Studio designer, versus it properly being shown in the Expression Blend 3. 

It seems that sizes and alignments are completely off in Visual Studio 2008 where everything appears correct, renders properly, and executes normally when created in Expression Blend 3.

Here’s an example of XAML as rendered in Visual Studio 2008:

image

and in Expression Blend 3:

image

Ignore the black background on the Expression screenshot, but notice that the buttons and all aspects are alligned properly, where the screenshot from Visual Studio 2008 is not.

Here is the XAML source:

<Window x:Class="QuickTwit.AccountWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="Accounts" mc:Ignorable="d" Height="300" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    <Grid>
        <ListBox Margin="12,12,0,124" Name="listAccounts" HorizontalAlignment="Left" Width="188" SelectionChanged="listAccounts_SelectionChanged" />
        <Button Height="23" HorizontalAlignment="Right" Margin="0,0,12,7" Name="buttonOK" VerticalAlignment="Bottom" Width="75" Click="buttonOK_Click">OK</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,20,12,0" Name="buttonDeleteAccount" VerticalAlignment="Top" Width="75" Click="buttonDeleteAccount_Click" IsEnabled="False">Delete</Button>
        <Rectangle Stroke="#FFC9C9C9" Margin="13,0,12,41" VerticalAlignment="Bottom" Height="75" RadiusX="10" RadiusY="10" Opacity="0.5">
            <Rectangle.Effect>
                <DropShadowEffect BlurRadius="1" ShadowDepth="1" Opacity="0.5"/>
            </Rectangle.Effect>
        </Rectangle>
        <TextBox Height="23" Margin="0,0,27,79" Name="textUsername" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="160" />
        <Label Height="28" HorizontalAlignment="Left" Margin="28,168,0,0" Name="label1" VerticalAlignment="Top" Width="69">Username:</Label>
        <Button x:Name="buttonAuthorize" VerticalAlignment="Bottom" Content="Authorize" Margin="0,0,27,49.04" HorizontalAlignment="Right" Width="75" Click="buttonAuthorize_Click" />
    </Grid>
</Window>

If you have seen this happen or know how to fix it, let me know.

3 comments on “Improper Rendering of XAML?”

  1. If you could post a link to the XAML file that exhibits this inconsistent behavior, it would be easier to understand the problem and suggest the solution (or bug fix?).
    Thanks, Rob

    Rob Relyea | WPF & Xaml Language Team
    robrelyea.com | /blog | /wpf | /xaml

  2. Justin - I'm a VS WPF Designer team member and I've reproduced your problem with the freshest of VS2010 bits and it is still a problem. I've entered an issue to track it, hopefully we can improve the rendering before we ship, but this will llikely still be an issue in Beta2.

    A workaround you could employ, just to make the rendering in the designer more accurate is to remove Window's size, set a fixed size on Window's child and set Window.SizeToContent="WidthAndHeight".

    This will make the window "shrink-wrap" around the window's child rather than have window's borders/etc take up space in the child. Should give you the same layout with better fidelity.

About JB

I've been a technologist for over 20 years, getting my start in IT with a large Fortune 100 international retailer in the 1990s. I love to talk about new technology, mobile devices, software development, photography, and the weather.  The opinions expressed on this blog are my own.

Follow me

Copyright © Justin Braun.  All rights reserved.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: