Silverlight Study Notes (4): Use of command controls

Source: Internet
Author: User

Learning controls are essential for developing Silverlight. The Silverlight controls are classified in the second section. If data access is not involved, you can first learn the control applications except progressbar, DataGrid, and mediaelement.

The following describes how to use the most basic and useful Command Control.

  • Button control:

First, open the created Project mysilverlightproject and open mainpage. XAML. The page content is displayed.

 

The red rounded rectangle in the figure is the place where we want to place the Command Control. The <stackpanel> shown by the arrow above is the layout control. Here, it is the container of the Command Control.

Open the toolbox, find the button control, and drag it to the position of the rectangle in the rounded corner. You can see that the button control has been placed. The following describes how to set the X: name, content, width, height, and margin attributes of a button in the XAML syntax mentioned in the second learning note, and specify the Click Event of a button:

 

Next, open the background. CS file of mainpage.

Write the following code in the generated btntest_click method:

 This. btntest. content = "clicked ";

After saving, you can run the program. The effect is displayed by default.

 

Click the button and the word displayed on the button changes to "clicked ".

 

Now we only use the background code to change the content of the button from the string to a string. In fact, using the content attribute, We can embed images, text, and other controls in the button. Let's Delete the content attribute in the button tag and add the following code:

 <Button.Content>

<TextBox Width="160"></TextBox>

</Button.Content>

Save and run the program. The following results are displayed:

 

You can put a textbox in the button. From this point, we can conclude that many attributes of the XAML tag can be directly used as the tag name. attribute as another tag. This is very different from the rigid HTML.

 

  • Repeatbutton

This control can control the occurrence time and method of the click event. It can be seen from its name that the control can repeatedly trigger a click event through a delay attribute and an interval attribute.

L The delay attribute is used to obtain or set the waiting time of the repeatbutton before the repeatbutton is clicked again. The unit is milliseconds. The default value is 250.

L The interval attribute is used to obtain or set the repetition interval of a click operation after repeatbutton starts repeatedly, in milliseconds. The default value is 250.

According to the previous introduction, place a repeatbutton under the button, and set the attributes and click events of X: name, content, width, height, and margin. In addition, we also need to set the delay and interval attributes:

  

Then, declare the variable count for the number of record clicks outside the repeatbutton_click method in the background CS file, and process the variables in the method:

 Int COUNT = 0;

Private void rbtntest_click (Object sender, routedeventargs E)

{

Count + = 1;

This. rbtntest. content = "click:" + Count + "times ";

}

Next, run the program and press the mouse on the repeatbutton to release the program. You can see that the clicked event is repeatedly executed:

 

From the process of learning command controls, we once again experienced the normalization and extensibility of XAML, learned multiple settings of control attributes, and applied the control event mechanism.

 

According to the plan, today I learned about Silverlight event processing, and it is still in the basic stage of applying Silverlight. It is still necessary to study it step by step to connect with the subsequent advanced applications.

 

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.