WPFで展開可能なメニューを作成【Expanderを使う】

Expanderを使い、以下のように項目を展開できるサンプルアプリを作成しました。

Expander(エキスパンダー)とは?

Expanderとは、コンテンツを表示する折りたたみ可能なコントロールのことです。ちょっと分かりにくいかもしれませんが、最初に紹介したサンプルアプリのようなことが可能になります。

https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.expander?view=netframework-4.8

サンプルコード

<Window x:Class="WpfAppExpander.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfAppExpander"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel>
            <Expander Header="メニュー1" IsEnabled="True" BorderBrush="Black">
                <StackPanel>
                    <TextBlock Text="項目1"/>
                    <TextBlock Text="項目2"/>
                </StackPanel>
            </Expander>
            <Expander Header="メニュー2" IsEnabled="True" BorderBrush="Red">
                <StackPanel>
                    <TextBlock Text="項目1"/>
                    <TextBlock Text="項目2"/>
                </StackPanel>
            </Expander>
            <Expander Header="メニュー3" IsEnabled="True" BorderBrush="Green">
                <StackPanel>
                    <TextBlock Text="項目1"/>
                    <TextBlock Text="項目2"/>
                </StackPanel>
            </Expander>
        </StackPanel>
    </Grid>
</Window>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA