1) memories
Yesterday's Silverlight Learning Series (1) The write is a little short, mainly because I feel a little tired. Today we will continue with yesterday. Today we will learn a little more.
We compiled the empty SL application created yesterday. We can find that there is a silverlightsample. xap file in the silverlightsample. Web project (that is, the web server. This is in the compilation process, Vs will automatically Copy the SL application to the Web server created by default .. Xap files are mainly used to hideCodeAnd some axml identifiers, as well as some static files and some image resources. To put it bluntly, it is a "compressed package", a standard. Net that can be recognized by Web servers.ProgramSet. For example, the. xap file is added.
2) learn how to add elements and process events on the page
When we run the SL application we created yesterday, we can find it is an empty page. Then we will add some controls to it. Open the mainpage. XAML page.
Add Button To cut down the image, I found it quite difficult to upload the image, and the speed was quite slow, so I directly pasted the code. This requires a lot of time for the code.
We can see that there is a default generated Grid . About Grid Keep it in mind next time, Grid And others Html The same tag, or control. You can add some attributes to the control. Assume that
This control adds the background color to blue, as long as Background = "blue" .
InButtonMediumX: Name = "btnyeanjay"HereX: NameEquivalentIn HTMLId.
We are doing Click A prompt box will appear when the event occurs. "Create an event handler" will automatically appear when you press Enter. Btnyeanjay_click Event.
Right-clickBtnyeanjay_clickYou can see the event handler in the navigation bar.
Jump to the background handler. At this time, vs automatically creates a button event for us.
We only need to add our business code in this event. Here, when I click the button, the text above the button is changed to tbird.
Now let's look at the running results:
When you click the button:
3) Layout of multiple controls
When the number of widgets on the Interface increases, we will consider the layout of the interface. In the layout of the interface, we will use the three most commonly used layout panels (Layout panels):
1.Canvas
2.Stackpanel
3.Grid
Let's talk about the first two, which will be explained tomorrow.
3.1AboutCanvasPanel
CanvasThe Panel is an absolute positioning of the control placed in it.
It can locate its internal control location by defining its own extended attributes. For example, you can defineCanvas. TopThis allows you to define controlsCanvasThe distance from the rock on the panel.
Let's take a look at the running results:
Use Canavs The Panel is only applicable to scenarios where there are few controls and the controls are relatively fixed. If there are more controls or the controls need to dynamically change their positions, we have to hand-write code to move the controls. We will explain the dynamic movement of controls in later learning. Therefore, we consider using the other two panels to implement multiple controls or dynamic mobile controls: Stackpanel And Grid.
1.1 about stackpanel
StakpanelBecause it will automatically stack the controls inside it into a line if you do not specify the arranged style at runtime, for example, we have defined threeButton
The running result is as follows:
Of course we can change Stackpanel Layout method, we set Orientation Attribute is H Orizontal In this way, the result is that the three buttons are arranged horizontally. The effect is as follows:
Today is here. Continue tomorrow ......
The company's network speed is better ......
Please refer to the third Silverlight Learning Series (3). Continue to learn more ......