silverlight之布局控件

传统布局(canvas, grid, stackpanel)

http://www.cnblogs.com/Terrylee/archive/2008/03/07/Silverlight2-step-by-step-part3.html

 

silverlight3新增的布局

http://space.itpub.net/12639172/viewspace-590777

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="Silverlight1.ColorChange"
    d:DesignWidth="640" d:DesignHeight="480">
 
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"></ColumnDefinition>
            <ColumnDefinition Width="200"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        
        <StackPanel Margin="20" Grid.Column="0">
            <TextBlock Text="red"></TextBlock><Slider Name="sliRed" Maximum="255" Value="255"></Slider>
            <TextBlock Text="blue"></TextBlock><Slider Name="sliblue" Maximum="255" Value="255"></Slider>
            <TextBlock Text="green"></TextBlock><Slider Name="sligreen" Maximum="255" Value="255"></Slider>
            <TextBlock Text="alpha"></TextBlock><Slider Name="slialpha" Maximum="255" Value="255"></Slider>
        </StackPanel>
        <StackPanel Grid.Column="1">
            <Rectangle x:Name="rect_Color" Height="80" Fill="Blue" Margin="20">
            </Rectangle>
            <TextBlock FontSize="12"><Run Text="Color"/></TextBlock>
            <TextBox x:Name="HexColor" Width="160" Height="30" Text="#FF6600" Margin="10,5" FontSize="11"/>
        </StackPanel>
    </Grid>
</UserControl>
<!--
margin属性 左上右下
Name相当于asp.net的ID
 -->
public ColorChange()
        {
            // 为初始化变量所必需
            InitializeComponent();
            changeColor((byte)slialpha.Value, (byte)sliRed.Value, (byte)sliblue.Value, (byte)sligreen.Value);
            slialpha.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliRed_ValueChanged);
            sliRed.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliRed_ValueChanged);
            sliblue.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliRed_ValueChanged);
            sligreen.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliRed_ValueChanged);
        }
 
        void sliRed_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            changeColor((byte)slialpha.Value, (byte)sliRed.Value, (byte)sliblue.Value, (byte)sligreen.Value);
        }
 
        private void changeColor(byte alpha, byte red,byte blue,byte green) {
            Color color = Color.FromArgb(alpha, red, green, blue);
 
            rect_Color.Fill = new SolidColorBrush(color);
            HexColor.Text = color.ToString();
        }

 

TerryLee_Silverlight2_0029_thumb.gif

转载于:https://www.cnblogs.com/jianjialin/archive/2010/07/11/1775073.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值