展开和折叠 WPF 扩展器
Expand and Collapse a WPF Expander
我在 DockPanel 控件中有两个 Expander,位于顶部的第一个 Expander 设置为 isExpanded true,而另一个 Expander 则不是。
我只想在 运行 时间内第一个 Expander 设置为 isExpanded false 时第二个 Expander 上升...
这是我的 XAML 代码:
<DockPanel LastChildFill="False" Margin="0,26,0,0" Background="#FF552D2D" HorizontalAlignment="Left" Width="149">
<StackPanel ScrollViewer.VerticalScrollBarVisibility="Auto">
<Expander x:Name="AdminManage" Header="Manage" Margin="0" Foreground="#FF14D0EE" Height="198" IsExpanded="True" Collapsed="AdminManage_Collapsed" Width="544">
<StackPanel x:Name="AdminStackPanel" Height="177" Margin="0,0,-2,0">
<Button Content="" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" Margin="23,0,0,0" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
</StackPanel>
</Expander>
<Expander Header="Account" Margin="0" VerticalAlignment="Top" Foreground="#FF14D0EE" Height="66">
<StackPanel Height="44" Margin="0,0,-2,0">
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
</StackPanel>
</Expander>
</StackPanel>
</DockPanel>
下面的意思是展开扩展器吗?
如果是这样,您可以像下面那样进行元素绑定。您还需要一个转换器来反转第一个扩展器的布尔值。
<Expander Header="Account" Margin="0" VerticalAlignment="Top" Foreground="#FF14D0EE" Height="66"
IsExpanded="{Binding IsExpanded, ElementName=AdminManage, Converter={StaticResource InvertBooleanConverter}"
<StackPanel Height="44" Margin="0,0,-2,0">
<!-- your content here -->
</StackPanel>
</Expander>
否则,如果你想交换它们的位置,你会想在 Grid
而不是 StackPanel
内添加扩展器,并更改附加的 Grid.Row
属性每当 IsExpanded
变化时扩展器
从 AdminManage Expander
中删除您的 Height
属性,我测试它会像预期的那样工作
我在 DockPanel 控件中有两个 Expander,位于顶部的第一个 Expander 设置为 isExpanded true,而另一个 Expander 则不是。
我只想在 运行 时间内第一个 Expander 设置为 isExpanded false 时第二个 Expander 上升...
这是我的 XAML 代码:
<DockPanel LastChildFill="False" Margin="0,26,0,0" Background="#FF552D2D" HorizontalAlignment="Left" Width="149">
<StackPanel ScrollViewer.VerticalScrollBarVisibility="Auto">
<Expander x:Name="AdminManage" Header="Manage" Margin="0" Foreground="#FF14D0EE" Height="198" IsExpanded="True" Collapsed="AdminManage_Collapsed" Width="544">
<StackPanel x:Name="AdminStackPanel" Height="177" Margin="0,0,-2,0">
<Button Content="" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" Margin="23,0,0,0" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
</StackPanel>
</Expander>
<Expander Header="Account" Margin="0" VerticalAlignment="Top" Foreground="#FF14D0EE" Height="66">
<StackPanel Height="44" Margin="0,0,-2,0">
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
</StackPanel>
</Expander>
</StackPanel>
</DockPanel>
下面的意思是展开扩展器吗?
如果是这样,您可以像下面那样进行元素绑定。您还需要一个转换器来反转第一个扩展器的布尔值。
<Expander Header="Account" Margin="0" VerticalAlignment="Top" Foreground="#FF14D0EE" Height="66"
IsExpanded="{Binding IsExpanded, ElementName=AdminManage, Converter={StaticResource InvertBooleanConverter}"
<StackPanel Height="44" Margin="0,0,-2,0">
<!-- your content here -->
</StackPanel>
</Expander>
否则,如果你想交换它们的位置,你会想在 Grid
而不是 StackPanel
内添加扩展器,并更改附加的 Grid.Row
属性每当 IsExpanded
变化时扩展器
从 AdminManage Expander
中删除您的 Height
属性,我测试它会像预期的那样工作