天天看點

windows phone (18) Border元素

xaml檔案:

<!--ContentPanel - 在此處放置其他内容--> 

        <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="邊框元素示例" VerticalAlignment="Center" HorizontalAlignment="Center"> 

                    <TextBlock.RenderTransform> 

                        <CompositeTransform Rotation="30"></CompositeTransform> 

                    </TextBlock.RenderTransform> 

                </TextBlock> 

            </Border> 

        </Grid> 

上面代碼中BorderBrush表示邊框顔色,它是Brush類型的,是以可以設定漸變畫刷;BorderThickness表示邊框的粗細,它 是Thickness類型的,Thickness是用于Margin和Padding的結構體,是以可以分别為上下左右設定不同個寬 度;CornerRadius表示設定邊框角的半徑,它是CornerRadius結構體,是以運作為四個角設定不同的圓角半徑值;可以看到 TextBlock直接鑲嵌在Border中,這是因為Border有個屬性是Child,因為Child屬性是Border的 ContentProperty屬性,是以Border.Child标記不是必須的,實作的效果:

下面的示例在隐藏檔案cs實作的四個角的圓角半徑不同,邊框的每個邊的粗細不同,并繪制邊框顔色xaml檔案代碼:

            <Border x:Name="bd" Background="DarkCyan" ManipulationDelta="bd_ManipulationDelta"> 

 隐藏檔案代碼:

// <summary> 

        /// 觸摸移動實作 

        /// </summary> 

        /// <param name="sender"></param> 

        /// <param name="e"></param> 

        private void bd_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) 

        { 

            //左上右下 

            Thickness thickNess = new Thickness(10, 20, 30, 40); 

            //設定不同的粗細 

            bd.BorderThickness = thickNess; 

            //設定左上,右上,左下,右下的圓角半徑值 

            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; 

            //實作邊框顔色 

            bd.BorderBrush = lgb; 

        } 

複制代碼 

效果:

本文轉自shenzhoulong  51CTO部落格,原文連結:http://blog.51cto.com/shenzhoulong/841791,如需轉載請自行聯系原作者

繼續閱讀