Wpf 在侧栏中单击按钮隐藏/折叠/可见dockpanel
我正在开发边栏wpf应用程序。侧栏有几个DockPanel。我的问题是,如何根据单击按钮在侧边栏中折叠/显示相同的DockPanel。例如:按钮1应该是折叠dockPanel1和里面的所有内容。按钮2应该显示它 以下是一个例子:Wpf 在侧栏中单击按钮隐藏/折叠/可见dockpanel,wpf,xaml,data-binding,Wpf,Xaml,Data Binding,我正在开发边栏wpf应用程序。侧栏有几个DockPanel。我的问题是,如何根据单击按钮在侧边栏中折叠/显示相同的DockPanel。例如:按钮1应该是折叠dockPanel1和里面的所有内容。按钮2应该显示它 以下是一个例子: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="370*"></ColumnDefinition>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="370*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Background="Black" x:Name="sidebarControl">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<DockPanel LastChildFill="False">
<Image DockPanel.Dock="Top" Source="{StaticResource logo}" />
<DockPanel DockPanel.Dock="Top" Height="160" Name="dockPanel1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<Label Content="Label1"></Label>
<Label Content="Label2"></Label>
</StackPanel>
<StackPanel Grid.Row="1">
<Label Content="Label3"></Label>
<Label Content="Label4"></Label>
</StackPanel>
</Grid>
</DockPanel>
<DockPanel DockPanel.Dock="Top" Height="160" Name="dockPanel2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<!-- other content -->
</StackPanel>
<StackPanel Grid.Row="1">
<!-- other content -->
</StackPanel>
</Grid>
</DockPanel>
</DockPanel>
</Grid>
</Grid>
我使用BooleantVisibilityConverter解决了这个问题。在ViewModel中,我放置了名为IsVisible的布尔属性。无论我在哪里更改IsVisible属性(设置为true或false),BooleanToVisibilityConverter类都要检查它并更改dockpanel可见性。这是我的密码:
<DockPanel DockPanel.Dock="Top" Height="160" Name="dockPanel1"
Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibility}, Mode=TwoWay}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<Label Content="Label1"></Label>
<Label Content="Label2"></Label>
</StackPanel>
<StackPanel Grid.Row="1">
<Label Content="Label3"></Label>
<Label Content="Label4"></Label>
</StackPanel>
</Grid>
</DockPanel>