0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visual Studio | WPF > IDE > デザイン時と実行時のウィンドウサイズの違い

Last updated at Posted at 2017-12-06
動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

デザイン時

qiita2.png

実行時

qiita.png

サイズの違い

  • デザイン時: 525 x 350
    • XAMLで指定した数値
  • 実行時: 510 x 340

XAMLファイル

MainWindow.xaml
<Window x:Class="WPF_TCPClient_171205.MainWindow"
        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"
        xmlns:local="clr-namespace:WPF_TCPClient_171205"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid Background="LightGray">
        <Button Name="B_send" Content="Send" HorizontalAlignment="Left" Margin="432,67,0,0" 
                VerticalAlignment="Top" Width="75" Click="B_send_Click"/>
        <Label Content="Text" HorizontalAlignment="Left" Margin="10,64,0,0" VerticalAlignment="Top"/>
        <TextBox Name="T_sendText" HorizontalAlignment="Left" Height="23" Margin="58,65,0,0" 
                 TextWrapping="Wrap" Text="Hello" VerticalAlignment="Top" Width="357"/>
        <TextBox Name="T_log" HorizontalAlignment="Left" Height="215" Margin="10,94,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="497"
                 VerticalScrollBarVisibility="Visible"
                 Text="{Binding LogText}"/>
        <Label Content="SendTo" HorizontalAlignment="Left" Margin="10,9,0,0" VerticalAlignment="Top"/>
        <TextBox Name="T_sendTo" HorizontalAlignment="Left" Height="23" Margin="68,10,0,0" 
                 TextWrapping="Wrap" Text="192.168.0.79" VerticalAlignment="Top" Width="120"/>
        <Label Content="port" HorizontalAlignment="Left" Margin="229,9,0,0" VerticalAlignment="Top"/>
        <TextBox Name="T_port" HorizontalAlignment="Left" Height="23" Margin="268,10,0,0" 
                 TextWrapping="Wrap" Text="7000" VerticalAlignment="Top" Width="120"/>

    </Grid>
</Window>

調整のコード > お薦めではない

code behindにて、初期化処理の後でWidthとHeightを10程度加えると、デザイン時のサイズに近づくが、実行環境により異なるかもしれないため、この方法はお薦めではない

        public MainWindow()
        {
            InitializeComponent();

            this.Height = 350 + 10;
            this.Width = 525 + 10;

qiita.png

他のバージョンのIDEでは問題があるのか不明。

関連1

Different size form WPF - Design mode vs Runtime mode

リンク先の回答にあるように、Width="525*"のような記載にしたら下記のエラーとなった。

FormatException: '525*' 文字列は、Length に変換できません。

"525*"などの書き方は「比率指定」だった。
https://qiita.com/7of9/items/eec0e8ce50149d087706
ColumnDefinitionなどでWidth="525*"というのは指定できるが、結果が自分の欲しいものにはならない。

関連2

C# WPF different size from IDE after debugging?

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?