質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/23 06:29

投稿

TN8001
TN8001

スコア10166

answer CHANGED
@@ -1,74 +1,74 @@
1
- `Grid`も`StackPanel`もそういう性質だから仕方がないのですが、いくつかアイデアがありました。
2
- [Hide grid row in WPF - Stack Overflow](https://stackoverflow.com/questions/2502178/hide-grid-row-in-wpf)
3
-
4
- xamlだけでやるとこんな感じです(2か所以上あるならコンバータのほうがいいですね)
5
-
6
- ```xaml
7
- <Window
8
- x:Class="Questions292804.MainWindow"
9
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
10
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
11
- Width="800"
12
- Height="450">
13
- <Window.Resources>
14
- <BooleanToVisibilityConverter x:Key="BoolVisibilityConverter" />
15
- </Window.Resources>
16
- <Grid>
17
- <Grid.RowDefinitions>
18
- <RowDefinition Height="Auto" />
19
- <RowDefinition Height="Auto" />
20
- <RowDefinition Height="Auto" />
21
- <RowDefinition>
22
- <RowDefinition.Style>
23
- <Style TargetType="RowDefinition">
24
- <Setter Property="Height" Value="*" />
25
- <Style.Triggers>
26
- <DataTrigger Binding="{Binding IsChecked, ElementName=R1}" Value="False">
27
- <Setter Property="Height" Value="0" />
28
- </DataTrigger>
29
- </Style.Triggers>
30
- </Style>
31
- </RowDefinition.Style>
32
- </RowDefinition>
33
- <RowDefinition Height="Auto" />
34
- <RowDefinition />
35
- <RowDefinition Height="Auto" />
36
- </Grid.RowDefinitions>
37
- <RadioButton
38
- Name="R1"
39
- Margin="5,5,5,5"
40
- Content="テスト"
41
- IsChecked="True" />
42
- <RadioButton
43
- Name="R2"
44
- Grid.Row="1"
45
- Margin="5,5,5,5"
46
- Content="テスト" />
47
- <Button
48
- x:Name="B1"
49
- Grid.Row="2"
50
- Margin="2,2,2,2"
51
- Content="テスト"
52
- Visibility="{Binding Path=IsChecked, ElementName=R1, Converter={StaticResource BoolVisibilityConverter}}" />
53
- <ListBox
54
- x:Name="L1"
55
- Grid.Row="3"
56
- Margin="2,2,2,2"
57
- Background="#FFBCF2F8" />
58
- <Label
59
- Grid.Row="4"
60
- Margin="2,2,2,2"
61
- Content="Log" />
62
- <ListBox
63
- x:Name="L2"
64
- Grid.Row="5"
65
- Margin="2,2,2,2"
66
- Background="#FFBCF2F8" />
67
- <Button
68
- x:Name="B2"
69
- Grid.Row="6"
70
- Margin="2,2,2,2"
71
- Content="テスト" />
72
- </Grid>
73
- </Window>
1
+ `Grid`も`StackPanel`もそういう性質だから仕方がないのですが、いくつかアイデアがありました。
2
+ [Hide grid row in WPF - Stack Overflow](https://stackoverflow.com/questions/2502178/hide-grid-row-in-wpf)
3
+
4
+ xamlだけでやるとこんな感じです(2か所以上あるならコンバータのほうがいいですね)
5
+
6
+ ```xml
7
+ <Window
8
+ x:Class="Questions292804.MainWindow"
9
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
10
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
11
+ Width="800"
12
+ Height="450">
13
+ <Window.Resources>
14
+ <BooleanToVisibilityConverter x:Key="BoolVisibilityConverter" />
15
+ </Window.Resources>
16
+ <Grid>
17
+ <Grid.RowDefinitions>
18
+ <RowDefinition Height="Auto" />
19
+ <RowDefinition Height="Auto" />
20
+ <RowDefinition Height="Auto" />
21
+ <RowDefinition>
22
+ <RowDefinition.Style>
23
+ <Style TargetType="RowDefinition">
24
+ <Setter Property="Height" Value="*" />
25
+ <Style.Triggers>
26
+ <DataTrigger Binding="{Binding IsChecked, ElementName=R1}" Value="False">
27
+ <Setter Property="Height" Value="0" />
28
+ </DataTrigger>
29
+ </Style.Triggers>
30
+ </Style>
31
+ </RowDefinition.Style>
32
+ </RowDefinition>
33
+ <RowDefinition Height="Auto" />
34
+ <RowDefinition />
35
+ <RowDefinition Height="Auto" />
36
+ </Grid.RowDefinitions>
37
+ <RadioButton
38
+ Name="R1"
39
+ Margin="5,5,5,5"
40
+ Content="テスト"
41
+ IsChecked="True" />
42
+ <RadioButton
43
+ Name="R2"
44
+ Grid.Row="1"
45
+ Margin="5,5,5,5"
46
+ Content="テスト" />
47
+ <Button
48
+ x:Name="B1"
49
+ Grid.Row="2"
50
+ Margin="2,2,2,2"
51
+ Content="テスト"
52
+ Visibility="{Binding IsChecked, ElementName=R1, Converter={StaticResource BoolVisibilityConverter}}" />
53
+ <ListBox
54
+ x:Name="L1"
55
+ Grid.Row="3"
56
+ Margin="2,2,2,2"
57
+ Background="#FFBCF2F8" />
58
+ <Label
59
+ Grid.Row="4"
60
+ Margin="2,2,2,2"
61
+ Content="Log" />
62
+ <ListBox
63
+ x:Name="L2"
64
+ Grid.Row="5"
65
+ Margin="2,2,2,2"
66
+ Background="#FFBCF2F8" />
67
+ <Button
68
+ x:Name="B2"
69
+ Grid.Row="6"
70
+ Margin="2,2,2,2"
71
+ Content="テスト" />
72
+ </Grid>
73
+ </Window>
74
74
  ```