WPF Expander 折叠栏

<Expander>
    <Expander.Header>
        <ToggleButton x:Name="expanderToggleButton" Click="ExpanderToggleButton_Click">
            <TextBlock Text="展开" />
        </ToggleButton>
    </Expander.Header>
    <Expander.Content>
        <!-- 这里是你想要展开的内容 -->
    </Expander.Content>
</Expander>

 C# 代码

private void ExpanderToggleButton_Click(object sender, RoutedEventArgs e)
{
    var toggleButton = sender as ToggleButton;
    var expander = toggleButton.TemplatedParent as Expander;
    if (expander != null)
    {
        expander.IsExpanded = toggleButton.IsChecked == true;
    }
}

 

参考:https://blog.csdn.net/lu2023_8_6/article/details/137022899

 

https://www.cnblogs.com/527289276qq/p/4379494.html

 

参考:https://blog.csdn.net/qq_42707143/article/details/122090882

 

posted @ 2024-05-25 10:06  microsoft-zhcn  阅读(114)  评论(0编辑  收藏  举报