WPF: implement the spring attribute in Windows Forms in the statusbar Control

Source: Internet
Author: User

In Windows Forms, you can adjust the spring attribute of toolstripstatuslabel to set the label in statusstrip to stretch (occupying all other space ):

 

In WPF, set horizontalcontentalignment of statusbaritem to stretch, but this can only be set for the last project:

<Statusbar>

<Statusbaritem>

<Button> A </button>

</Statusbaritem>

<Statusbaritem>

<Button> B </button>

</Statusbaritem>

<Statusbaritem horizontalcontentalignment = "stretch">

<Button> C </button>

</Statusbaritem>

</Statusbar>

 

Result:

 

 

If you want a more complex layout, You can redefine itemspanel of itemscontrol, for example, the slightly complex statusbar below:

<Stackpanel>

<! -- Set the statusbaritem style. The default value of horizontalcontentalignment is left -->

<Stackpanel. Resources>

<Style targettype = "statusbaritem">

<Setter property = "borderbrush" value = "red"/>

<Setter property = "borderthickness" value = "1"/>

<Setter property = "margin" value = "1"/>

<Setter property = "horizontalcontentalignment" value = "stretch"/>

<Setter property = "verticalcontentalignment" value = "stretch"/>

</Style>

</Stackpanel. Resources>

<Statusbar>

<! -- Set itemspanel to dockpanel -->

<Statusbar. itemspanel>

<Itemspaneltemplate>

<Dockpanel/>

</Itemspaneltemplate>

</Statusbar. itemspanel>

<Statusbaritem dockpanel. Dock = "TOP">

<Button> A </button>

</Statusbaritem>

<Statusbaritem dockpanel. Dock = "right">

<Button> B </button>

</Statusbaritem>

<Statusbaritem>

<Button> C </button>

</Statusbaritem>

</Statusbar>

</Stackpanel>

 

Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.