Reputation: 6552
I have been having an issue with 2 applications. The size and position of my controls in the designer don't make the positions when the application is running.
I'm I missing something here? Sorry not sure how to google that to find my answers.
The control issue always seems to be with the buttons
Here is an example
Designer
Running
Here is the button code.
<Button x:Name="btnPortal" Background="{x:Null}" BorderBrush="{x:Null}" Margin="732,32,-425,642" BorderThickness="0" Cursor="Hand" Click="btnPortal_Click" RenderTransformOrigin="0.5,0.5" IsEnabled="False">
<Button.Template>
<ControlTemplate>
<Image Source="Resources/portal.png" Margin="0,0,709,0"/>
</ControlTemplate>
</Button.Template>
</Button>
Upvotes: 0
Views: 643
Reputation: 1496
The problem is with your margin.
<Button x:Name="btnPortal" Margin="732,32,-425,642" ...
<Image Source="Resources/portal.png" Margin="0,0,709,0"/>
That says for your button, position it 732 pixels from the left, 32 pixels from the right, -425 pixels from the right, and 642 pixels from the bottom of the parent object. And then for the Image, 0 left, 0 top, 709 from the right, and 0 from the bottom of the button's edges.
In another way, it's relative to the parent objects when you use margins. In the designer, you should see something like d:DesignWidth="XXXX" d:DesignHeight="XXXX". That's setting how the width and height looks in your designer, but when it's running the UI objects will be laid our based on the runtime sizes, etc.
Change it to something more reasonable. I suggest you go here and read up on how to set the layout.
http://wpftutorial.net/LayoutProperties.html
Upvotes: 1