Visual Studio/WPF > 컨트롤 > ToolBar

운영 환경
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

@ WPF 4.5 입문 by 오타 카즈키
No.4119/9985

ToolBar 컨트롤은, 이름 그대로, 어플리케이션의 툴바를 구현하기 위한 컨트롤입니다. ToolBar 컨트롤은, ToolBarTray 컨트롤내에 배치하는 형태로 구현합니다.

시도해 보았다.

XAML
<Window x:Class="_170425_t1840_toolbar.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:_170425_t1840_toolbar"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid Margin="0, 30, 0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <ToolBarTray Grid.Row="0">
            <ToolBar x:Name="toolbar1">
                <Button Content="Button1"/>
                <Separator/>
                <Button Content="Button2"/>
                <Button Content="Button3"/>
            </ToolBar>
            <ToolBar x:Name="toolbar2">
                <Button Content="Button4"/>
                <Button Content="Button5"/>
                <Button Content="Button6"/>
            </ToolBar>
        </ToolBarTray>
        <Button Grid.Row="1" Content="Button1" 
                Click="reset_toolbar"
                MaxHeight="30" MaxWidth="100"/>
    </Grid>
</Window>

MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _170425_t1840_toolbar
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void reset_toolbar(object sender, RoutedEventArgs e)
        {
            toolbar1.BandIndex = 0;
            toolbar2.BandIndex = 1;
        }
    }
}

Button을 눌렀을 때 배치를 되돌려 보았습니다.

좋은 웹페이지 즐겨찾기