B
B
buzzi8882014-02-09 22:05:10
XAML
buzzi888, 2014-02-09 22:05:10

What's with the weird indentation when creating elements in Visual Studio?

Why does Studio set margins for elements?
For example, I throw a button on an empty form without changing anything and get this code in xaml

<Button Content="Button" HorizontalAlignment="Left" Margin="761,364,0,0" VerticalAlignment="Top"/>

You have to remove the margin for each element, only in this case the positioning works correctly.
Visual Studio Express 2013, C# Project -> Windows Store -> Empty Application (XAML)
Here is the full page code:
<Page
    x:Class="camApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:camApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button Content="Button" HorizontalAlignment="Left" Margin="761,364,0,0" VerticalAlignment="Top"/>
    </Grid>
</Page>

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Doshevsky, 2014-02-10
@buzzi888

Because when you put an element in a certain place on the form, in order for it to be there, the studio sets the appropriate indents, otherwise it will be in the upper left corner.
I would advise not to use a designer, but to write xaml code by hand, so you have better control over the markup

B
buzzi888, 2014-02-11
@buzzi888

Thank you. Can't this behavior be disabled?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question