我想问一下如何自动生成包含标签和组合框的网格。我想要的是,一旦用户在组合框 1 中选择了一个选项,该方法将自动生成另一个网格(包含组合框 2)等等。
下面是我目前拥有的代码,现在我很想创建一个事件驱动的方法来在当前组合框中调用 IsSelected 后显示下一个网格。
<Grid x:Name="comp1" Margin="0,84,230,345">
<Label Content="Test Component 1:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,4,0,0"/>
</Grid>
<Grid x:Name="comp2" Margin="0,127,230,302" Visibility="Hidden">
<Label Content="Test Component 2:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,4,0,0"/>
</Grid>
<Grid x:Name="comp3" Margin="0,166,230,262" Visibility="Hidden">
<Label Content="Test Component 3:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB3" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,5,0,0"/>
</Grid>
<Grid x:Name="comp4" Margin="0,205,230,222" Visibility="Hidden">
<Label Content="Test Component 4:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB4" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,6,0,0"/>
</Grid>
<Grid x:Name="comp5" Margin="0,245,230,182" Visibility="Hidden">
<Label Content="Test Component 5:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB5" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,6,0,0"/>
</Grid>
<Grid x:Name="comp6" Margin="0,281,230,145" Visibility="Hidden">
<Label Content="Test Component 6:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,3,0,0"/>
<ComboBox x:Name="testCompCB6" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,10,0,-3"/>
</Grid>
<Grid x:Name="comp7" Margin="0,328,230,100" Visibility="Hidden">
<Label Content="Test Component 7:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB7" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,5,0,0"/>
</Grid>
<Grid x:Name="comp8" Margin="0,370,230,59" Visibility="Hidden">
<Label Content="Test Component 8:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB8" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,3,0,0"/>
</Grid>
<Grid x:Name="comp9" Margin="0,406,230,15" Visibility="Hidden">
<Label Content="Test Component 9:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ComboBox x:Name="testCompCB9" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,12,0,0"/>
</Grid>