回答編集履歴
3
見直しキャンペーン中
answer
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
確かにあまりいい方法はなさそうです。
|
2
|
-
|
3
|
-
> コントロールの大きさを計算して、MinHight、MinWidthを設定する
|
4
|
-
|
5
|
-
一時的に`SizeToContent="WidthAndHeight"`にすれば計算する必要はありません。
|
6
|
-
その時のサイズを入れるだけです。
|
7
|
-
しかしタイトルバーの高さ等はユーザー設定によるので、環境によってずれてしまいます。
|
8
|
-
`SizeToContent="WidthAndHeight"`を入れたままでいい(初期サイズがぴったりサイズでいい)なら`Loaded`イベントあたりで`MinWidth = Width`等とできます。
|
9
|
-
|
10
|
-
```
|
11
|
-
<Window
|
12
|
-
x:Class="Questions288908.MainWindow"
|
13
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
14
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
15
|
-
Loaded="Window_Loaded"
|
16
|
-
SizeToContent="WidthAndHeight">
|
17
|
-
<Window.Resources>
|
18
|
-
<Style TargetType="Button">
|
19
|
-
<Setter Property="Width" Value="200" />
|
20
|
-
<Setter Property="Height" Value="150" />
|
21
|
-
<Setter Property="Margin" Value="20" />
|
22
|
-
<Setter Property="Content" Value="Button" />
|
23
|
-
</Style>
|
24
|
-
</Window.Resources>
|
25
|
-
<StackPanel>
|
26
|
-
<StackPanel Orientation="Horizontal">
|
27
|
-
<Button />
|
28
|
-
<Button />
|
29
|
-
<Button />
|
30
|
-
</StackPanel>
|
31
|
-
<StackPanel Orientation="Horizontal">
|
32
|
-
<Button />
|
33
|
-
<Button />
|
34
|
-
<Button />
|
35
|
-
</StackPanel>
|
36
|
-
</StackPanel>
|
37
|
-
</Window>
|
38
|
-
```
|
39
|
-
|
40
|
-
```
|
41
|
-
using System.Windows;
|
42
|
-
|
43
|
-
namespace Questions288908
|
44
|
-
{
|
45
|
-
public partial class MainWindow : Window
|
46
|
-
{
|
47
|
-
public MainWindow()
|
48
|
-
{
|
49
|
-
InitializeComponent();
|
50
|
-
}
|
51
|
-
|
52
|
-
private void Window_Loaded(object sender, RoutedEventArgs e)
|
53
|
-
{
|
54
|
-
MinWidth = Width;
|
55
|
-
MinHeight = Height;
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
```
|
60
|
-
---
|
61
|
-
|
62
|
-
そもそも論なのですがWPFでのデザインでは、コントロールに固定サイズを入れることはせずに、ウィンドウサイズに合わせて伸縮させるのが一般的です。
|
63
|
-
もちろん操作不能に小さくならないように、ウィンドウに`MinWidth`等を入れることは普通です。
|
1
|
+
確かにあまりいい方法はなさそうです。
|
2
|
+
|
3
|
+
> コントロールの大きさを計算して、MinHight、MinWidthを設定する
|
4
|
+
|
5
|
+
一時的に`SizeToContent="WidthAndHeight"`にすれば計算する必要はありません。
|
6
|
+
その時のサイズを入れるだけです。
|
7
|
+
しかしタイトルバーの高さ等はユーザー設定によるので、環境によってずれてしまいます。
|
8
|
+
`SizeToContent="WidthAndHeight"`を入れたままでいい(初期サイズがぴったりサイズでいい)なら`Loaded`イベントあたりで`MinWidth = Width`等とできます。
|
9
|
+
|
10
|
+
```xml
|
11
|
+
<Window
|
12
|
+
x:Class="Questions288908.MainWindow"
|
13
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
14
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
15
|
+
Loaded="Window_Loaded"
|
16
|
+
SizeToContent="WidthAndHeight">
|
17
|
+
<Window.Resources>
|
18
|
+
<Style TargetType="Button">
|
19
|
+
<Setter Property="Width" Value="200" />
|
20
|
+
<Setter Property="Height" Value="150" />
|
21
|
+
<Setter Property="Margin" Value="20" />
|
22
|
+
<Setter Property="Content" Value="Button" />
|
23
|
+
</Style>
|
24
|
+
</Window.Resources>
|
25
|
+
<StackPanel>
|
26
|
+
<StackPanel Orientation="Horizontal">
|
27
|
+
<Button />
|
28
|
+
<Button />
|
29
|
+
<Button />
|
30
|
+
</StackPanel>
|
31
|
+
<StackPanel Orientation="Horizontal">
|
32
|
+
<Button />
|
33
|
+
<Button />
|
34
|
+
<Button />
|
35
|
+
</StackPanel>
|
36
|
+
</StackPanel>
|
37
|
+
</Window>
|
38
|
+
```
|
39
|
+
|
40
|
+
```cs
|
41
|
+
using System.Windows;
|
42
|
+
|
43
|
+
namespace Questions288908
|
44
|
+
{
|
45
|
+
public partial class MainWindow : Window
|
46
|
+
{
|
47
|
+
public MainWindow()
|
48
|
+
{
|
49
|
+
InitializeComponent();
|
50
|
+
}
|
51
|
+
|
52
|
+
private void Window_Loaded(object sender, RoutedEventArgs e)
|
53
|
+
{
|
54
|
+
MinWidth = Width;
|
55
|
+
MinHeight = Height;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
60
|
+
---
|
61
|
+
|
62
|
+
そもそも論なのですがWPFでのデザインでは、コントロールに固定サイズを入れることはせずに、ウィンドウサイズに合わせて伸縮させるのが一般的です。
|
63
|
+
もちろん操作不能に小さくならないように、ウィンドウに`MinWidth`等を入れることは普通です。
|
64
64
|
その際は中身の大きさを積み重ねてボトムアップで計算しているのではなく、ウィンドウの最小サイズはこんなもんかな?とトップダウンで決めているような気がします(マイクロソフトのアプリ等を見る限り。もっと小さくできそうなのに小さくならない
|
2
1行多かったw
answer
CHANGED
@@ -33,11 +33,6 @@
|
|
33
33
|
<Button />
|
34
34
|
<Button />
|
35
35
|
</StackPanel>
|
36
|
-
<StackPanel Orientation="Horizontal">
|
37
|
-
<Button />
|
38
|
-
<Button />
|
39
|
-
<Button />
|
40
|
-
</StackPanel>
|
41
36
|
</StackPanel>
|
42
37
|
</Window>
|
43
38
|
```
|
1
コード追加
answer
CHANGED
@@ -7,6 +7,61 @@
|
|
7
7
|
しかしタイトルバーの高さ等はユーザー設定によるので、環境によってずれてしまいます。
|
8
8
|
`SizeToContent="WidthAndHeight"`を入れたままでいい(初期サイズがぴったりサイズでいい)なら`Loaded`イベントあたりで`MinWidth = Width`等とできます。
|
9
9
|
|
10
|
+
```xaml
|
11
|
+
<Window
|
12
|
+
x:Class="Questions288908.MainWindow"
|
13
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
14
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
15
|
+
Loaded="Window_Loaded"
|
16
|
+
SizeToContent="WidthAndHeight">
|
17
|
+
<Window.Resources>
|
18
|
+
<Style TargetType="Button">
|
19
|
+
<Setter Property="Width" Value="200" />
|
20
|
+
<Setter Property="Height" Value="150" />
|
21
|
+
<Setter Property="Margin" Value="20" />
|
22
|
+
<Setter Property="Content" Value="Button" />
|
23
|
+
</Style>
|
24
|
+
</Window.Resources>
|
25
|
+
<StackPanel>
|
26
|
+
<StackPanel Orientation="Horizontal">
|
27
|
+
<Button />
|
28
|
+
<Button />
|
29
|
+
<Button />
|
30
|
+
</StackPanel>
|
31
|
+
<StackPanel Orientation="Horizontal">
|
32
|
+
<Button />
|
33
|
+
<Button />
|
34
|
+
<Button />
|
35
|
+
</StackPanel>
|
36
|
+
<StackPanel Orientation="Horizontal">
|
37
|
+
<Button />
|
38
|
+
<Button />
|
39
|
+
<Button />
|
40
|
+
</StackPanel>
|
41
|
+
</StackPanel>
|
42
|
+
</Window>
|
43
|
+
```
|
44
|
+
|
45
|
+
```C#
|
46
|
+
using System.Windows;
|
47
|
+
|
48
|
+
namespace Questions288908
|
49
|
+
{
|
50
|
+
public partial class MainWindow : Window
|
51
|
+
{
|
52
|
+
public MainWindow()
|
53
|
+
{
|
54
|
+
InitializeComponent();
|
55
|
+
}
|
56
|
+
|
57
|
+
private void Window_Loaded(object sender, RoutedEventArgs e)
|
58
|
+
{
|
59
|
+
MinWidth = Width;
|
60
|
+
MinHeight = Height;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
```
|
10
65
|
---
|
11
66
|
|
12
67
|
そもそも論なのですがWPFでのデザインでは、コントロールに固定サイズを入れることはせずに、ウィンドウサイズに合わせて伸縮させるのが一般的です。
|