Windows Phone (18) border element

Source: Internet
Author: User


The border class analyzes the border, background, and the two of an object at the same time]

XAML file:

<!-ContentPanel-Put other content here->
        <Grid x: Name = "ContentPanel" Grid.Row = "1" Margin = "12,0,12,0">
            <Border Background = "DarkCyan" BorderBrush = "Coral" BorderThickness = "20" CornerRadius = "19">
                <TextBlock x: Name = "tbShow" Text = "Example of border elements" VerticalAlignment = "Center" HorizontalAlignment = "Center">
                    <TextBlock.RenderTransform>
                        <CompositeTransform Rotation = "30"> </ CompositeTransform>
                    </TextBlock.RenderTransform>
                </ TextBlock>
            </ Border>
        </ Grid>
In the above code, BorderBrush represents the border color, which is of the Brush type, so you can set a gradient brush; BorderThickness represents the thickness of the border, it is of the Thickness type, and Thickness is the structure for Margin and Padding, so it can be up, down, left, and right Set different widths; CornerRadius means to set the radius of the corner of the border, it is the CornerRadius structure, so set different corner radius values for the four corners; you can see that TextBlock is directly embedded in the Border, because Border has a property It is Child, because the Child property is the ContentProperty property of the Border, so the Border.Child tag is not necessary, the effect achieved:

 

 It should be noted that the Child property can only set an element of the UIElement type, so we can put some textblock, image, etc., if you want to expand the element in the border, you can use the panel stackpanel, canvas, grid, nesting other elements inside ; As can be seen, the border we define is the entire fill grid, this is because the horizontal and horizontal alignment of the border element and the vertical position VerticalAlignment default value is Stretch, so it will stretch and fill the entire parent element, so generally set the width of the border And high

 In the following example, the corner radius of the four corners implemented in the hidden file cs is different, the thickness of each side of the border is different, and the border color is drawn

Xaml file code:

<!-ContentPanel-Put other content here->
        <Grid x: Name = "ContentPanel" Grid.Row = "1" Margin = "12,0,12,0">
            <Border x: Name = "bd" Background = "DarkCyan" ManipulationDelta = "bd_ManipulationDelta">
                <TextBlock x: Name = "tbShow" Text = "Example of border elements" VerticalAlignment = "Center" HorizontalAlignment = "Center">
                    <TextBlock.RenderTransform>
                        <CompositeTransform Rotation = "30"> </ CompositeTransform>
                    </TextBlock.RenderTransform>
                </ TextBlock>
            </ Border>
        </ Grid>
Hidden file code:

/// <summary>
        /// Touch mobile implementation
        /// </ summary>
        /// <param name = "sender"> </ param>
        /// <param name = "e"> </ param>
        private void bd_ManipulationDelta (object sender, ManipulationDeltaEventArgs e)
        {
            // Upper left and lower right
            Thickness thickNess = new Thickness (10, 20, 30, 40);
            // Set different thickness
            bd.BorderThickness = thickNess;
            // Set the corner radius values for upper left, upper right, lower left, and lower right
            CornerRadius cornerRadius = new CornerRadius (10, 20, 30, 40);
            bd.CornerRadius = cornerRadius;

            LinearGradientBrush lgb = new LinearGradientBrush ();
            GradientStopCollection gsc = new GradientStopCollection ();
            GradientStop gs1 = new GradientStop ();
            gs1.Color = Color.FromArgb (122, 102, 213, 167);
            gs1.Offset = 0.2;
            gsc.Add (gs1);
            GradientStop gs2 = new GradientStop ();
            gs2.Color = Color.FromArgb (102, 102, 133, 167);
            gs2.Offset = 0.7;
            gsc.Add (gs2);
            lgb.GradientStops = gsc;
            // Realize the border color
            bd.BorderBrush = lgb;
        }
 effect:

 

 

Walk a thousand miles

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.