Windows Phone (23) scrollviewer Element

Source: Internet
Author: User

 

The scrollviewer class indicates a scroll area that can contain other visible elements. Generally, it is used as an extension when the screen width and height are insufficient. It is called a scroll bar in reference books, by default, the vertical scroll bar is visible, and the horizontal scroll bar is not displayed. verticalscrollbarvisibility and horizontalscrollbarvisibility are two attributes. The values of these two attributes are members of the scrollbarvisibility enumeration. [Author: Shenzhou Dragon]

Visible displays the scroll bar; Hidden does not display the scroll bar; Auto displays the scroll bar when needed; disabled is visible but does not respond to the touch event. These two attributes are also used below, in the following example, the program title is changed to show better results.

XAML code:

<! -- Titlepanel contains the application name and page title --> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <stackpanel. resources> <style X: key = "ststyle" targettype = "textblock"> <setter property = "texttrimming" value = "wordellipsis"> </setter> <setter property = "fontsize" value = "23"> </setter> <setter property = "foreground" value = "blueviolet"> </setter> <setter property = "horizontalalignment" value = "center"> </setter> </style> </stackpanel. resources> <textblock X: Name = "applicationtitle" text = "Smile" style = "{staticresource ststyle}"/> </stackpanel>

We can see that we have customized styles. The principle defined here is to define and use them first, that is, the textblock in the above Code cannot be above the style. If so, the system will report an error;

The XAML code of the content area:

<! -- Contentpanel-place other content here --> <grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <grid. resources> <style X: key = "paragraphstyle" targettype = "textblock"> <setter property = "textwrapping" value = "Wrap"> </setter> <setter property = "margin" value = "5"> </setter> <setter property = "fontsize" value = "19"> </setter> </style> </grid. resources> <scrollviewer padding = "5"> <stackpanel> <textblock style = "{s Taticresource paragraphstyle} "> today, we get off work at noon one day, because the weather is good. everyone had a meal in the dining room and went out for dinner. I asked, How can I fix the worst problem for others? Everyone laughed and talked about their views. <linebreak/> after a while, I saw my niece cook. When she spoke, she asked: What are you talking about? I said: If you hate a person, what do you think is the best way to fix it. she opened her mouth and said, "Let's get a meal from someone else and I will say: It will take a few days for the skin to hurt. What is this. she said again: Find a few people to humiliate him, huh, huh! As time passes, the trauma of the mind will gradually become better? When she heard it, she put the bowl in her hand on the flower platform, Put both hands into the waist, and the right hand went up, hey! Marry him! I was speechless at the time. She said: Isn't it enough for me to torture him all my life? <Linebreak/> since then, she has an extra nickname (Erma) </textblock> <line strokethickness = "9" stroke = "blue" X1 = "0" Y1 = "20" X2 = "480" y2 = "20"> </line> <textblock style = "{staticresource paragraphstyle}"> <run> fall in love with a young man, if a man wants to test whether a woman can keep her alive, he asks his girlfriend: "If you walk down the street late at night, a man will kiss you. What do you do?" His girlfriend replied, "I will resist and slap him in the face ." The man asked, "What if another drunk man wants to hug you all at once ?" His girlfriend replied, "I will fight hard to prevent him from doing anything ." After hearing this, The man nodded happily and asked, "What would you do if another handsome man asks you that ?" My girlfriend listened and replied, "You need to know, </run> <run fontstyle =" italic "> a woman's resistance is limited after all !" </Run> </textblock> <line stroke = "blue" strokethickness = "9" X1 = "0" Y1 = "20" X2 = "480" y2 = "20"> </line> <textblock X: name = "" style = "{staticresource paragraphstyle}"> I received a text message: "My wife is about to start sleeping with other husbands at today, I had to wait happily to wash, change, and bathe. He couldn't bring a gun." After reading this, I was puzzled. Why is there such a cheap person. Later I saw the sender, and I went there to give birth to a baby! </Textblock> </stackpanel> </scrollviewer> </GRID>

We can see that the custom style is also used here, with the internal and external margins respectively 5. The book says this is helpful for reading, but after seeing the effect, it really feels good; stackpanel used in the Code is vertical by default. You can set orientation = "horizontal" to arrange child elements horizontally; before each paragraph, the Unicode Character "padding" is provided to indicate the width of the row to which the paragraph belongs.

Line class

The above Code also uses line to draw a straight line between two points. The basic attributes to be satisfied are x1, x2, Y1, Y2, where X1, Y1 as the starting point, X2, y2 serves as the end point and is connected to a straight line. You can use stroke to set the color and strokethickness to set the display width. Here, the result is relatively rough;

See:

 

Scrollviewer is displayed vertically by default, so the effect is as shown above, so we can set the effect of the horizontal scroll bar. Simply add horizontalscrollbarvisibility = "visible" to the scrollviewer label, and the code is not pasted, let's get the results.

 

Note that we have set automatic line feed in the style, but because we set the horizontal scroll bar display, the concept of line feed is gone; but I want to know how long the text is displayed in the horizontal direction if the text does not wrap. the fact may not be as good as we think.

 

When the scroll bar is about half reached, the text above will no longer be displayed, so if the text is too long, even if the horizontal scroll bar is set, it will not be completely displayed, this is an extreme situation and is generally not used

Then, when the width of the horizontal scrolling area is reached, a touch event is added.

Private void sv1_manipulationcompleted (Object sender, manipulationcompletedeventargs e) {This. applicationtitle. Text = "horizontal scroll area width:" + sv1.scrollablewidth. tostring ();}

 

Differences between versions 7.0 and 7.1:

 

Action

Windows Phone OS 7.0 APP/Windows Phone OS 7.0
Device

 

Windows Phone OS 7.0 or Windows Phone OS 7.1 APP/Windows Phone OS 7.1
Device

Scrollviewer updates attributes on the UI thread during scrolling

The attribute is updated when the value is changed.

The attribute is updated when the user raises his finger, or when the user is dragging, shaking, or tapping screen 1/4 in any direction.

 

Manipulationdelta
Ui when dragging insideEvents on the thread
Scrollviewer.

Process events using elements in scrollviewer.

Events are not triggered because they are in the input thread.

 

 

 

 

The first one is understandable, and the second one is because there is scroll, So touch movement is the event manipulationdelta will not be triggered, this proves that I used this event to obtain the horizontal scroll width and the value is 0,

 

If the application depends on Windows Phone OS 7.0, you can cancel performance improvement
On scrollviewer, Set
Set the manipulationmode attribute
Control. The following sample code demonstrates the specific practices.

<ListBox itemssource = "{binding items}" scrollviewer. manipulationmode = "control" Height = "652" canvas. Top = "80">

 

May 1 is off. Relax.

Related Article

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.