0
我有六個堆棧面板元素,它們都是通過單獨的切換按鈕切換的,這是我需要的。但是,當用戶打開其中一個堆疊面板時,我想關閉其他所有堆疊面板,只顯示他們點擊的那個面板。WPF在6個堆棧面板之間切換可見性,並在打開時隱藏所有其他面板
<Grid HorizontalAlignment="Left" Height="504" Margin="-1,1,0,0" VerticalAlignment="Top" Width="760">
<Grid.Resources>
<BooleanToVisibilityConverter x:Key="boolConverter" />
</Grid.Resources>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FF45B8F9" Margin="1,-1,0,0"/>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FFF95545" Margin="636,0,0,-1" Visibility="{Binding ElementName=button, Path=IsChecked, Converter={StaticResource boolConverter}}"/>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FFF9F945" Margin="507,-1,0,0" Visibility="{Binding ElementName=button_Copy, Path=IsChecked, Converter={StaticResource boolConverter}}"/>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FF76F945" Margin="378,-1,0,0" Visibility="{Binding ElementName=button1, Path=IsChecked, Converter={StaticResource boolConverter}}"/>
<ToggleButton x:Name="button" Content="Green" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="105" Click="button_Click"/>
<ToggleButton x:Name="button_Copy" Content="Yellow" HorizontalAlignment="Left" Margin="10,55,0,0" VerticalAlignment="Top" Width="105" Click="button_Click"/>
<ToggleButton x:Name="button1" Content="Red" HorizontalAlignment="Left" Margin="10,114,0,0" VerticalAlignment="Top" Width="105"/>
</Grid>
你真的應該使用RowDefinitions和ColumnDefinitions一格。你說你有6個stackpanels,但我只看到4.另外,togglebuttons的數量不等於stackpanels的數量(雖然我認爲每個stackpanel應該有每個togglebutton)。 – Hopeless
我保持濃縮我認爲應用於3的解決方案可以應用於3個面板。其中一個面板是主控面板。 –