回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
`ListView`に`GridViewColumn`を自動調整する機能はないので、サイズ変更時にカラム幅を計算し再設定するコードを書くことになります。
|
2
|
-
「wpf gridviewcolumn autosize」「wpf gridviewcolumn 自動」等で検索するといくつかヒットします。
|
3
|
-
|
4
|
-
手軽に導入できないかとNuGetで調べたところ、`WPF.ListViewLayoutManager`というのがありました。簡単に試した範囲では問題なく動作しました。
|
5
|
-
[ListView Layout Manager - CodeProject](https://www.codeproject.com/Articles/25058/ListView-Layout-Manager)
|
6
|
-
|
7
|
-
`ctrl:なんちゃら`というのを付けるだけで自動調整してくれます。
|
8
|
-
|
9
|
-
```
|
10
|
-
<Window
|
11
|
-
x:Class="Questions275037.MainWindow"
|
12
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
13
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
14
|
-
xmlns:ctrl="clr-namespace:Itenso.Windows.Controls.ListViewLayout;assembly=Itenso.Windows.Controls.ListViewLayout"
|
15
|
-
Width="800"
|
16
|
-
Height="450">
|
17
|
-
<DockPanel>
|
18
|
-
<StackPanel DockPanel.Dock="Top">
|
19
|
-
<Button Click="list_add_Click" Content="add" />
|
20
|
-
<Button Click="list_get_Click" Content="get" />
|
21
|
-
</StackPanel>
|
22
|
-
<ListView
|
23
|
-
x:Name="lv"
|
24
|
-
ctrl:ListViewLayoutManager.Enabled="true"
|
25
|
-
SelectionMode="Single">
|
26
|
-
<ListView.View>
|
27
|
-
<GridView>
|
28
|
-
|
29
|
-
<!-- 自動で広がるカラム -->
|
30
|
-
<GridViewColumn
|
31
|
-
Width="550"
|
32
|
-
ctrl:RangeColumn.IsFillColumn="true"
|
33
|
-
DisplayMemberBinding="{Binding Path=[0]}"
|
34
|
-
Header="hoge" />
|
35
|
-
|
36
|
-
<!-- 最小サイズがあるカラム -->
|
37
|
-
<GridViewColumn
|
38
|
-
ctrl:RangeColumn.MinWidth="50"
|
39
|
-
DisplayMemberBinding="{Binding Path=[1]}"
|
40
|
-
Header="fuga" />
|
41
|
-
|
42
|
-
<!-- 固定サイズのカラム -->
|
43
|
-
<GridViewColumn
|
44
|
-
ctrl:FixedColumn.Width="50"
|
45
|
-
DisplayMemberBinding="{Binding Path=[1]}"
|
46
|
-
Header="fuga" />
|
47
|
-
</GridView>
|
48
|
-
</ListView.View>
|
49
|
-
</ListView>
|
50
|
-
</DockPanel>
|
51
|
-
</Window>
|
1
|
+
`ListView`に`GridViewColumn`を自動調整する機能はないので、サイズ変更時にカラム幅を計算し再設定するコードを書くことになります。
|
2
|
+
「[wpf gridviewcolumn autosize](https://www.google.co.jp/search?q=wpf+gridviewcolumn+autosize)」「[wpf gridviewcolumn 自動](https://www.google.co.jp/search?q=wpf+gridviewcolumn+%E8%87%AA%E5%8B%95)」等で検索するといくつかヒットします。
|
3
|
+
|
4
|
+
手軽に導入できないかとNuGetで調べたところ、`WPF.ListViewLayoutManager`というのがありました。簡単に試した範囲では問題なく動作しました。
|
5
|
+
[ListView Layout Manager - CodeProject](https://www.codeproject.com/Articles/25058/ListView-Layout-Manager)
|
6
|
+
|
7
|
+
`ctrl:なんちゃら`というのを付けるだけで自動調整してくれます。
|
8
|
+
|
9
|
+
```xml
|
10
|
+
<Window
|
11
|
+
x:Class="Questions275037.MainWindow"
|
12
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
13
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
14
|
+
xmlns:ctrl="clr-namespace:Itenso.Windows.Controls.ListViewLayout;assembly=Itenso.Windows.Controls.ListViewLayout"
|
15
|
+
Width="800"
|
16
|
+
Height="450">
|
17
|
+
<DockPanel>
|
18
|
+
<StackPanel DockPanel.Dock="Top">
|
19
|
+
<Button Click="list_add_Click" Content="add" />
|
20
|
+
<Button Click="list_get_Click" Content="get" />
|
21
|
+
</StackPanel>
|
22
|
+
<ListView
|
23
|
+
x:Name="lv"
|
24
|
+
ctrl:ListViewLayoutManager.Enabled="true"
|
25
|
+
SelectionMode="Single">
|
26
|
+
<ListView.View>
|
27
|
+
<GridView>
|
28
|
+
|
29
|
+
<!-- 自動で広がるカラム -->
|
30
|
+
<GridViewColumn
|
31
|
+
Width="550"
|
32
|
+
ctrl:RangeColumn.IsFillColumn="true"
|
33
|
+
DisplayMemberBinding="{Binding Path=[0]}"
|
34
|
+
Header="hoge" />
|
35
|
+
|
36
|
+
<!-- 最小サイズがあるカラム -->
|
37
|
+
<GridViewColumn
|
38
|
+
ctrl:RangeColumn.MinWidth="50"
|
39
|
+
DisplayMemberBinding="{Binding Path=[1]}"
|
40
|
+
Header="fuga" />
|
41
|
+
|
42
|
+
<!-- 固定サイズのカラム -->
|
43
|
+
<GridViewColumn
|
44
|
+
ctrl:FixedColumn.Width="50"
|
45
|
+
DisplayMemberBinding="{Binding Path=[1]}"
|
46
|
+
Header="fuga" />
|
47
|
+
</GridView>
|
48
|
+
</ListView.View>
|
49
|
+
</ListView>
|
50
|
+
</DockPanel>
|
51
|
+
</Window>
|
52
52
|
```
|