Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DockPanel with Toolbar and Statusbar

Tags:

c#

wpf

dockpanel

I'm learning WPF and am trying to have a form that consists of a toolbar at the top, a statusbar at the bottom and the rest will be occupied by controls used for data entry.

This is what I have so far:

<Window x:Class="MyApp.MyForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MyForm" Height="346" Width="459">
    <DockPanel>
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar>
                <Button Command="New" Content="New" />
                <Button Command="Open" Content="Open" />
                <Button Command="Save" Content="Save" />
            </ToolBar>
        </ToolBarTray>
    </DockPanel>
</Window>

How do I add a statusbar at the bottom and another panel that will occupy the rest of the form?

like image 576
Ivan-Mark Debono Avatar asked Oct 18 '25 17:10

Ivan-Mark Debono


1 Answers

You can use DockPanel to arrange your controls. like this Toolbar will be dock at top, Statusbar at bottom and rest space will be assigned to datagrid because we have set the "LastChildFill" to true in dockpanel.

<Window x:Class="MyApp.MyForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyForm" Height="346" Width="459">
<DockPanel LastChildFill="True">
    <ToolBarTray DockPanel.Dock="Top">
        <ToolBar>
            <Button Command="Edit" Content="Edit" />
            <Button Command="Delete" Content="Delete" />
            <Button Command="Refresh" Content="Refresh" />
        </ToolBar>
    </ToolBarTray>
<StatusBar Name="statusbar" DockPanel.Dock="Bottom">statusbar</StatusBar>
<DataGrid Name="grdEmployees" ItemsSource="{Binding EmpCollection}" />

enter image description here

like image 172
Ehsan Hafeez Avatar answered Oct 20 '25 08:10

Ehsan Hafeez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!