Windows phone hidden elements

Source: Internet
Author: User
Tags visibility
We will also use hiding an element in wp to achieve a certain effect. I have just read the article and will share it with you [author: shenzhenlong]
Visibility
This attribute can easily hide an element. However, the visibility attribute is not of the boolean type but is of the visibility type and contains the enumeration types of two members, visibility and collapsed:
By default, the attribute is displayed as visible. When set to collapsed, the element size changes to 0. When set to collapsed, the element to which this attribute belongs is not involved in the event, in addition, you cannot obtain the focus. If you do not obtain the focus, you cannot perform a hit test.
 
Xaml code:
The code is as follows: Copy code
<! -- ContentPanel-place other content here -->
<Grid x: Name = "ContentPanel" Grid. Row = "1" Margin = "12, 0, 12, 0"
              >
<TextBlock x: Name = "tb1" Text = "tb1 display" VerticalAlignment = "Center" HorizontalAlignment = "Center"> </TextBlock>
<TextBlock x: Name = "tb2" Text = "tb2 display" Visibility = "Collapsed" verticalignment = "Center"> </TextBlock>
</Grid>
Before adding Visibility = "Collapsed"
 
After adding visibility = "Collapsed"
However, if this attribute is used during the layout process, changing the size of an element to 0 may affect the layout;
Opactity
Yes, this is the property. I did not expect it to be this property before I saw it, but think about it carefully. When Opactity = "0, you can set the transparency of an element to the lowest, and you will not be able to see it. However, this element actually exists. Therefore, this attribute can be used without affecting the layout, and the element will not disappear.
Xaml code:
The code is as follows: Copy code
<Grid x: Name = "ContentPanel" Grid. Row = "1" Margin = "12, 0, 12, 0"
              >
<TextBlock x: Name = "tb1" Text = "tb1 display" VerticalAlignment = "Center" HorizontalAlignment = "Center"> </TextBlock>
<TextBlock x: Name = "tb2" Text = "tb2 display" Opacity = "0" verticalignment = "Center" ManipulationDelta = "tb2_ManipulationDelta"> </TextBlock>
</Grid>
Effect after running:
 
Like the previous image, we can see from the code that we have defined a touch movement event to see if it will be implemented. The code for hiding a file is relatively simple, as shown below:
The code is as follows: Copy code
Private void tb2_ManipulationDelta (object sender, ManipulationDeltaEventArgs e)
        {
This. PageTitle. Text = "still corresponding event ";
        }
Effect:
 
Like the above sentence, the system still responds to the event (it seems that it is nonsense to write this event test :))
Okay, just add this sentence, and add the attribute IsHitTestVisible = "False" so that it will not respond to the user's touch operation;
 
 
In layout, the opacity attribute does not have the visibility attribute. If you need to use frequent layout nesting, try to avoid opacity. If you use the above two attributes in grid and other elements, the elements contained in gird will also apply these two attributes;
If the rendertransform attribute is applied to the panel, the child element in the panel will also be affected. However, if the rendertransform attribute is set in the subpanel, the parent panel will ignore the effect of the child panel transformation;
 
 
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.