zoukankan      html  css  js  c++  java
  • silverlight(二)样式

    在silverlight中有三种样式:一个是在本控件设置样式一个是在UserControl.Resources设置样式,最后一个是在App.xaml中设置样式

    1.在本控件设置样式:

    代码:

    <Canvas Height="100" Background="Yellow" HorizontalAlignment="Left" Margin="66,93,0,0" Name="canvas1" VerticalAlignment="Top" Width="60" />

    2.在UserControl.Resources设置样式

    <UserControl.Resources>
            <Style x:Key="canvasstyle"  TargetType="Canvas">
                <Setter Property="Background"  Value="Blue"/>
            </Style>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
            <Canvas Height="100" Background="Yellow" HorizontalAlignment="Left" Margin="66,93,0,0" Name="canvas1" VerticalAlignment="Top" Width="60" />
            <Canvas   Height="100" Style="{StaticResource canvasstyle}" HorizontalAlignment="Left" Margin="201,98,0,0" Name="canvas2" VerticalAlignment="Top" Width="87" />
            <Canvas Height="100" Style="{StaticResource canvasstyle}" HorizontalAlignment="Left" Margin="57,12,0,0" Name="canvas3" VerticalAlignment="Top" Width="200" />
        </Grid>

    在这里有的人会想,我想要设置每个控件的颜色,不是要每个都这只一遍?有没有办法一个样式设置所有相同的控件? 答案是有的。这个只需要把样式的x:Key="canvasstyle" 拿掉就行了 如下代码:

    <UserControl.Resources>
            <Style  TargetType="Canvas">
                <Setter Property="Background"  Value="Blue"/>
            </Style>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
            <Canvas Height="100" Background="Yellow" HorizontalAlignment="Left" Margin="66,93,0,0" Name="canvas1" VerticalAlignment="Top" Width="60" />
            <Canvas   Height="100"  HorizontalAlignment="Left" Margin="201,98,0,0" Name="canvas2" VerticalAlignment="Top" Width="87" />
            <Canvas Height="100"  HorizontalAlignment="Left" Margin="57,12,0,0" Name="canvas3" VerticalAlignment="Top" Width="200" />
        </Grid>

    3.在App.xaml中设置样式

    只需要把刚才写的样式放在里面就行了

     <Application.Resources>
            <Style   TargetType="Canvas" >
                <Setter   Property="Background" Value="Blue"/>
            </Style>
        </Application.Resources>

  • 相关阅读:
    numpy中的随机数模块
    windows下用pycharm安装tensorflow简易教程
    Tensor是神马?为什么还会Flow?
    TypeError: 'NoneType' object is not subscriptable
    pycharm 运行错误信息显示乱码
    pycharm terminal 'import' 不是内部或外部命令,也不是可运行的程序
    pycharm 出现 "PEP:8 expected 2 blank lines ,found 0"
    TensorFlow升级1.4:Cannot remove entries from nonexistent file libsite-pack
    win10 python3.5 自动补全设置
    python pip NameError:name 'pip' is not defined”
  • 原文地址:https://www.cnblogs.com/xuxiaorong/p/2420351.html
Copyright © 2011-2022 走看看