Implementation and loading of the Silverlight Toolbar

Source: Internet
Author: User


Toolbarbutton XAML Code As follows:
<Button X: class = "xcenter. Framework. Client. toolbarbutton"
2 xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml">
4 <button. Resources>
5 <storyboard X: Name = "Activate">
6 <doubleanimation begintime = "0: 0" Duration = "0: 0. 2" storyboard. targetproperty = "width"
7 to = "28" X: Name = "activewidth"/>
8 <doubleanimation begintime = "0: 0" Duration = "0: 0. 2" storyboard. targetproperty = "height"
9 to = "28" X: Name = "activeheight"/>
10 <doubleanimation begintime = "0: 0" Duration = "0: 0. 2" storyboard. targetproperty = "opacity"
11 to = "1.0" type = "codeph" text = "/codeph"/>
12 </storyboard>
13 <storyboard X: Name = "deactivate">
14 <doubleanimation begintime = "0: 0" Duration = "0: 0. 2" storyboard. targetproperty = "width"
15 to = "24" X: Name = "deactivewidth"/>
16 <doubleanimation begintime = "0: 0" Duration = "0: 0. 2" storyboard. targetproperty = "height"
17 to = "24" X: Name = "deactiveheight"/>
18 <doubleanimation begintime = "0: 0" Duration = "0: 0. 2" storyboard. targetproperty = "opacity"
19 to = "0.75"/>
20 </storyboard>
21 </button. Resources>
22 <button. content>
23 <image X: Name = "IMG"> </image>
24 </button. content>
25 </button>

You can see that toolbarbutton inherits from the button class, and there is only one image control on the interface that is used to display icons, except for animation resources. The XAML. CS code will not be pasted, mainly the leave and enter events of the mouse, and the icons will be zoomed in and restored with the defined animation.

The following describes the XAML code of toolbar.

<Usercontrol X: class = "xcenter. Framework. Client. toolbar"
2 xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml">
4 <stackpanel orientation = "horizontal" background = "Transparent"
5 x: Name = "buttonpanel" verticalignment = "center">
6 </stackpanel>
7 </usercontrol>

1. the toolbar code is simpler, that is, a stackpanel serves as the toolbarbutton container. The main logic is to obtain a unique ID to determine whether the toolbar has been loaded.
Let's take a look at the usage. I have defined an interface for loading toolbar,

/// <Summary>
2 // The toolbar interface is supported.
3 /// </Summary>
4 public interface itoobarable
5 {
6 /// <summary>
7 // obtain the grid of the toolbar container
8 /// </Summary>
9 /// <returns> </returns>
10 toolbar gettoolbar ();
11
12 /// <summary>
13 // obtain the unique entity of the toolbar
14 /// </Summary>
15 /// <returns> </returns>
16 string gettoolbarid ();
17}

This interface must be implemented on the page (usercontrol) to add the toolbar function. Because my main interface is located in the page class of xcenter. UI, and the page class is similar to a frame, When you click the tree menu on the left, load the main interface instance of the specified module in tabcontrol through reflection. When loading an instance, you can call the method in itoolbarable:
Tabitem. content = UC;
// Add a toolbar
If (UC is itoobarable)
{
Addtoolbar (UC );
}
Private void addtoolbar (usercontrol UC)
2 {
3 if (UC = NULL)
4 return;
5 itoobarable toolbar = (itoobarable) UC;
6 if (! When whelper. session. containskey (sessionconst. sk_toobarid)
7 | windowhelper. session [sessionconst. sk_toobarid] = NULL)
8 {
9 // The current environment does not have a toolbar. Add it directly.
10 toolbarcontainer. Children. Add (toolbar. gettoolbar ());
11 when whelper. session. Add (sessionconst. sk_toobarid, toolbar. gettoolbarid ());
12}
13 else
14 {
15 // The current environment has a toolbar, but it is not the toolbar of this interface
16 string toolbarid = define whelper. session [sessionconst. sk_toobarid]. tostring ();
17 if (! Toolbarid. Equals (toolbar. gettoolbarid ()))
18 {
19 toolbarcontainer. Children. Clear ();
20 toolbarcontainer. Children. Add (toolbar. gettoolbar ());
21 then whelper. session [sessionconst. sk_toobarid] = toolbar. gettoolbarid ();
22}
23}
24}

You can see that toobarid is used to determine whether the toolbar has been loaded.
As to whether the button in the toolbar is available, it simply loops through the toolbarbutton in toobar and sets enable. This is okay if there are not many buttons in toobar. If this method is used, the problem cannot be solved.

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.