如何在WPF中设置小的扩展标头并扩展内容?

时间:2019-03-11 07:52:44

标签: c# wpf xaml expander

我正在创建自定义虚拟键盘​​。当前,对于所有标点符号,我将其设置在另一个网格上。扩展器的内容似乎可以保留标点视图。但是目前,如果我希望扩展器的内容能够查看其中的内容,则需要设置内容的大小。

如何使按钮尺寸可以扩展,单击后内容将扩展到更大的尺寸?

OSK

如何使扩展器的尺寸如下图所示(黄色矩形),但是单击扩展器时,内容将像GIF一样扩展?

enter image description here

<Button HorizontalAlignment="Left" Height="52.25" Margin="0,238.5,0,0" VerticalAlignment="Top" Width="168.187" Background="#FF3C3C3C" FontFamily="Arial" FontSize="18" BorderBrush="#FF6E6E6E">
    <Expander Header="?!#" ExpandDirection="Up" Background="{x:Null}" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Top">
        <!-- How add content grid which can be expander at full while maintaining the expander header to small size? -->
    </Expander>
</Button>

1 个答案:

答案 0 :(得分:2)

我建议您将扩展键盘的Button放在另一个Panel中,并用Visibility控制Panel的{​​{1}}。 / p>

当您使用ToggleButton(如您所用)来握住扩展键盘时,可以很容易地完成以下操作:

Expander

或者您可以使用<Grid Background="Gray" Height="300"> <!-- Basic Keyboard Buttons can be placed here --> <Button HorizontalAlignment="Left" Margin="0,0,0,30" VerticalAlignment="Top" Content="Put some Buttons from the BASIC Keyboard here"/> <!-- Button to bring the extanded Keyboard into view --> <ToggleButton x:Name="ExtendedKeyboardActive" HorizontalAlignment="Left" VerticalAlignment="Center" Content="?!#" Width="50"/> <!-- Extended Keyboard (Note: I would rather use a simple <Grid/> instead of an <Expander/> but it is up to you)--> <Expander VerticalAlignment="Bottom" ExpandDirection="Up" IsExpanded="{Binding IsChecked, ElementName=ExtendedKeyboardActive}" Background="LightGray"> <Grid Height="300"> <!-- Content of the extaned Keyboard --> <Button HorizontalAlignment="Left" Margin="0,0,0,30" VerticalAlignment="Top" Content="Put some Buttons from the EXTENDED Keyboard here"/> <!-- Button ti hide the extended Keyboard (optional if it the 'ExtendedKeyboardActive' is not covered over by the extended Keyboard Grid) --> <ToggleButton IsChecked="{Binding IsChecked, ElementName=ExtendedKeyboardActive}" Width="50" HorizontalAlignment="Left" VerticalAlignment="Center" Content="ABC" /> </Grid> </Expander> </Grid> ,因为PopUp具有始终显示且不需要的箭头-圆圈-事物(谢谢@ Bradley Uffner)。

Expander