WPF simulates Windows 7 desktop taskbar

Source: Internet
Author: User

This program is similar to the Windows 7 desktop taskbar. When you double-click a shortcut on the desktop, a new subinterface is opened and a taskbar icon linked to this interface is created in the taskbar, when you move the cursor to the icon on the taskbar, the popup real-time image thumbnail is displayed. When you click the taskbar icon, the interface can be maximized or minimized, as shown in the following figure. The source code is downloaded from here.

Use visualbrush to fill the real-time image of the sub-interface into the rectangle when you create a thumbnail of this taskbar interface.

1 rectangle emptyrectangle = new rectangle
2 {
3 width = 250d,
4 Height = 130d,
5 fill = new visualbrush {visual = Child },
6 margin = New thickness (2)
7 };

We also used two border to simulate the rounded corner of the thumbnail in the Windows 7 taskbar.

Use rounded corner

// Apply the rounded corner to the thumbnail of the popup interface of the taskbar
Border visualborder = new border
{
Borderbrush = brushes. Transparent,
Borderthickness = New thickness (1 ),
Cornerradius = new cornerradius (10 ),
Margin = New thickness (10 ),
Height = 150d,
Width = 270d,
Child = emptyrectangle,
Horizontalalignment = horizontalalignment. Center,
Verticalalignment = verticalignment. Center,
Background = This. findresource ("transparentcolor") as lineargradientbrush
};
// Apply the rounded corner to the background of the thumbnail on the popup interface of the taskbar
Border host = new border
{
Borderbrush = brushes. Transparent,
Borderthickness = New thickness (1 ),
Cornerradius = new cornerradius (8 ),
Child = visualborder,
Horizontalalignment = horizontalalignment. Center,
Verticalalignment = verticalignment. Center,
Background = This. findresource ("thumbnailbackground") as imagebrush
}; Copy the code

Define a thumbnail of A tooltip used to host the interface

Tooltip

// Add a tooltip for the host subinterface
Tooltip visualtooltip = new tooltip
{
Content = host,
Background = brushes. Transparent,
Borderbrush = brushes. Transparent,
Placement = placementmode. Top,
Horizontalcontentalignment = horizontalalignment. Center,
Verticalcontentalignment = verticalignment. Center,
Hasdropshadow = false,
Verticaloffset = 3
};
// Design the popup delay of tooltip to 20 ms
Tooltipservice. setinitialshowdelay (thumbnail, 20 );
Thumbnail. tooltip = visualtooltip; copy the code

Define events. When the subinterface is closed, move the icons on the taskbar from the taskbar. When you click the mouse on the taskbar icon, the interface is maximized or minimized.

Define events

// When the opened sub-interface is closed, you need to remove the icon on this interface from the taskbar
Child. Closed + = delegate
{
This. statusbar. Children. Remove (hostborder );
};
// Maximize or minimize the subinterface when you click the task icon on the taskbar
Hostborder. mouseleftbuttondown + = delegate (Object sender, mousebuttoneventargs E)
{
If (E. clickcount = 1)
{
If (child. windowstate = windowstate. Minimized)
{
// The Sub-interface is displayed normally.
Child. windowstate = windowstate. normal;
Child. topmost = true;
}
Else
// Minimize the subinterface
Child. windowstate = windowstate. minimized;
}
}; Copy the code

This program is easy to implement, but it should be noted that when adding the sub-interface taskbar icon to the taskbar, it should be added in the order from top to bottom, so as to avoid repeated Rendering
The leaf point of the logical tree,

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.