zoukankan      html  css  js  c++  java
  • silverlight制作虚线的边框

    <Grid>
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="g">
    <Canvas>
    <Rectangle RadiusX="5" RadiusY="5"
    Width="{Binding ElementName=g, Path=ActualWidth}"
    Height="{Binding ElementName=g, Path=ActualHeight}"
    Stroke="Blue" StrokeDashArray="5,2,1,2" StrokeThickness="2"/>
    </Canvas>
    <TextBlock Margin="10,7,10,7" Text="aaa" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
    </Grid>

    效果图:

    image

    公共样式:

     1 <Style TargetType="ContentControl" x:Key="myBorder">
     2 
     3 <Setter Property="Template">
     4 
     5 <Setter.Value>
     6 
     7 <ControlTemplate>
     8 
     9 <Grid x:Name="g"
    10 
    11 Background="{TemplateBinding ContentControl.Background}"
    12 
    13 Width="{TemplateBinding ContentControl.Width}"
    14 
    15 Height="{TemplateBinding ContentControl.Height}">
    16 
    17 <Canvas>
    18 
    19 <Rectangle RadiusX="5" RadiusY="5"
    20 
    21 Width="{Binding ElementName=g, Path=ActualWidth}"
    22 
    23 Height="{Binding ElementName=g, Path=ActualHeight}"
    24 
    25 Stroke="{TemplateBinding ContentControl.BorderBrush}"
    26 
    27 StrokeDashArray="5,2,1,2"
    28 
    29 StrokeThickness="{TemplateBinding ContentControl.BorderThickness}"/>
    30 
    31 </Canvas>
    32 
    33 <ContentPresenter Margin="5" Content="{TemplateBinding ContentControl.Content}"/>
    34 
    35 </Grid>
    36 
    37 </ControlTemplate>
    38 
    39 </Setter.Value>
    40 
    41 </Setter>
    42 
    43 </Style>

    http://www.cnblogs.com/sosoft/

    使用示例:

    <ContentControl Margin="10" HorizontalAlignment="Center" VerticalAlignment="Center"

    BorderThickness="2" BorderBrush="Blue" Style="{StaticResource myBorder}">

    <TextBlock Text="abc"/>

    </ContentControl>

  • 相关阅读:
    从“窃听门”事件解读手机Rootkit攻击
    一款好用的开源信息安全管理系统演示(视频)
    P1908-逆序对
    P1010-幂次方
    P1226-快速幂
    P1433-吃奶酪
    ACM模板——玄学逐字符输入输出
    P1434-滑雪
    P1118-数字三角形
    P1443-马的遍历
  • 原文地址:https://www.cnblogs.com/sosoft/p/3489927.html
Copyright © 2011-2022 走看看