编程语言
首页 > 编程语言> > c# – 如何设置Expander Direction水平滑动而不是垂直滑动?

c# – 如何设置Expander Direction水平滑动而不是垂直滑动?

作者:互联网

我知道System.Windows.Controls.Expander是WPF中的另一个“headered”内容控件,类似于System.Windows.Controls.GroupBox.一个优点是Expanders能够通过折叠隐藏其内容,并通过扩展显示内容.

我的问题是,如果我希望我的扩展器从左到右或从右到左水平滑动而不是垂直滑动怎么办?让我们说我有以下扩展器:

<StackPanel x:Name="RightPanel">
    <Expander x:Name="ExportExpander">
        <StackPanel>
            <TextBlock Name="x" Text="Element One"/>
            <Button Name="y" Content="Element Two"/>
        </StackPanel>
    </Expander>
</StackPanel> 

解决方法:

您可以像这样使用Expander的ExpandDirection属性:

<Expander x:Name="ExportExpander" ExpandDirection="Right">

正确的代码如下所示:

<StackPanel x:Name="RightPanel">
    <Expander x:Name="ExportExpander" ExpandDirection="Right">
        <StackPanel Orientation="Horizontal">
            <TextBlock Name="x" Text="Element One"/> <!--Textblock has Text property-->
            <Button Name="y" Content="Element Two"/>
        </StackPanel>
    </Expander>
</StackPanel>     

标签:c,wpf,xaml,expander
来源: https://codeday.me/bug/20190528/1167413.html