Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 在侧栏中单击按钮隐藏/折叠/可见dockpanel_Wpf_Xaml_Data Binding - Fatal编程技术网

Wpf 在侧栏中单击按钮隐藏/折叠/可见dockpanel

Wpf 在侧栏中单击按钮隐藏/折叠/可见dockpanel,wpf,xaml,data-binding,Wpf,Xaml,Data Binding,我正在开发边栏wpf应用程序。侧栏有几个DockPanel。我的问题是,如何根据单击按钮在侧边栏中折叠/显示相同的DockPanel。例如:按钮1应该是折叠dockPanel1和里面的所有内容。按钮2应该显示它 以下是一个例子: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="370*"></ColumnDefinition>

我正在开发边栏wpf应用程序。侧栏有几个DockPanel。我的问题是,如何根据单击按钮在侧边栏中折叠/显示相同的DockPanel。例如:按钮1应该是折叠dockPanel1和里面的所有内容。按钮2应该显示它

以下是一个例子:

<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>