我想根据组合框中的选择显示不同的堆栈面板。想法是折叠所有不需要的堆栈面板。
组合框看起来像这样:
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock Text="New Question" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center" Margin="10"/>
<ComboBox x:Name="ComboBox" MaxWidth="200" IsTextSearchEnabled="True" SelectedValuePath="Choice">
<ComboBox.Items>
<ComboBoxItem>Test</ComboBoxItem>
<ComboBoxItem>SliderQuestion</ComboBoxItem>
<ComboBoxItem>OpenQuestion</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
</StackPanel>
因此,如果选择了Sliderquestion,我想显示包含sliderquestion设置元素的堆栈面板。
我现在有一个基本的Stackpanel设置,看起来像这样。
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel.Resources>
<Style x:Key="ForSliderQuestion" TargetType="{x:Type StackPanel}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=ComboBox, Path=SelectedValue}" Value="SliderQuestion">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=ComboBox, Path=SelectedValue}" Value="OpenQuestion">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<StackPanel Style="{DynamicResource ForSliderQuestion}">
<TextBlock Text="Test" FontSize="30"></TextBlock>
</StackPanel>
</StackPanel>
老实说,这应该不难,但我仍然是新手,所以我知道什么。有人愿意帮助吗?谢谢!