Silverlight2 控件布局(笔记)

 

使用一个嵌套的 Canvas 创建了蓝色矩形框包围下的红色矩形效果。
<Border Background="Coral" Width="300" Padding="10" CornerRadius="20">
    <TextBlock FontSize="16">Text Surrounded by a Border</TextBlock>
</Border>

StackPanel垂直排列

<StackPanel Margin="20">
    <Rectangle Fill="Red" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Blue" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Green" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Purple" Width="50" Height="50" Margin="5" />
</StackPanel>

水平排列
<StackPanel Orientation="Horizontal" Margin="20">
    <Rectangle Fill="Red" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Blue" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Green" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Purple" Width="50" Height="50" Margin="5" />
</StackPanel>


Grid 是 Silverlight 提供的灵活程度最高、功能最为强大的容器对象。Grid 定义一个由列和行组成的灵活的网格区域。Grid 的列和行分别是使用 ColumnDefinition 和 RowDefinition 定义的。默认情况下,网格的子级放置在第一行和第一列中。可以通过设置 Grid..::.Column 和 Grid..::.Row 附加属性,在 Grid 的特定单元格中定位对象。

<Grid x:Name="LayoutRoot" Background="Coral" Width="300" Height="100" ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Grid.Column="0" Grid.Row="0" Text="First Name" HorizontalAlignment="Center" VerticalAlignment="Center" />
    <TextBlock Grid.Column="0" Grid.Row="1" Text="Last Name" HorizontalAlignment="Center" VerticalAlignment="Center" />
    <TextBox Grid.Column="1" Grid.Row="0" Margin="15,10,15,10" />
    <TextBox Grid.Column="1" Grid.Row="1" Margin="15,10,15,10" />

</Grid>


最后作了一个练习

<Grid x:Name="LayoutRoot"  Width="800" Height="600"  ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition  />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="60"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Column="1" Grid.Row="0" Text="利润表" FontSize="30"  HorizontalAlignment="Center" VerticalAlignment="Center" />
        <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
            <TextBlock Text="纳税人识别号" FontSize="14"></TextBlock>
            <TextBox Width="170"></TextBox>
        </StackPanel>
        <StackPanel Grid.Row="1" Grid.Column="2" Orientation="Horizontal">
            <TextBlock HorizontalAlignment="Right" Text="企业名称" FontSize="14"></TextBlock>
            <TextBox Width="170"></TextBox>
        </StackPanel>

        <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal">
            <TextBlock Text="纳税企业类型" FontSize="14"></TextBlock>
            <ComboBox x:Name="QYLX" Width="170"></ComboBox>
        </StackPanel>

        <StackPanel HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
            <TextBlock Text="所属期起" FontSize="14"></TextBlock>
            <basics:DatePicker Width="194"></basics:DatePicker>
        </StackPanel>

        <StackPanel Grid.Row="2" Grid.Column="2" Orientation="Horizontal">
            <TextBlock Text="所属期止" FontSize="14"></TextBlock>
            <basics:DatePicker Width="194"></basics:DatePicker>
        </StackPanel>

        <TextBlock Grid.Column="0" Grid.Row="3" Text="项目" FontSize="16"  HorizontalAlignment="Center" VerticalAlignment="Center" />
        <TextBlock Grid.Column="1" Grid.Row="3" Text="本期金额" FontSize="16"  HorizontalAlignment="Center" VerticalAlignment="Center" />
        <TextBlock Grid.Column="2" Grid.Row="3" Text="上年同期金额" FontSize="16"  HorizontalAlignment="Center" VerticalAlignment="Center" />
       
        <TextBlock Grid.Column="0" Grid.Row="4" Text="一、营业收入" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="5" Text="  减:营业成本" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="6" Text="    营业税金及附加" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="7" Text="           销售费用" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="8" Text="       管理费用" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="9" Text="  加:公允价值变动收益" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="10" Text="          投资收益" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="11" Text="二、营业利润" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="12" Text="  加:营业外收入" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="13" Text="  减:营业外支出" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Column="0" Grid.Row="14" Text="三、利润总额" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center" />

        <TextBox Grid.Column="1" Grid.Row="4" Margin="2,1,2,1" Background="AliceBlue" x:Name="tb1" TextChanged="TextBox_TextChanged"/>
        <TextBox Grid.Column="1" Grid.Row="5" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="1" Grid.Row="6" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="1" Grid.Row="7" Margin="2,1,2,1" Background="AliceBlue" />
        <TextBox Grid.Column="1" Grid.Row="8" Margin="2,1,2,1" Background="AliceBlue" />
        <TextBox Grid.Column="1" Grid.Row="9" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="1" Grid.Row="10" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="1" Grid.Row="11" Margin="2,1,2,1" Background="GreenYellow" />
        <TextBox Grid.Column="1" Grid.Row="12" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="1" Grid.Row="13" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="1" Grid.Row="14" Margin="2,1,2,1" Background="GreenYellow" />

        <TextBox Grid.Column="2" Grid.Row="4" Margin="2,1,2,1" Background="AliceBlue" />
        <TextBox Grid.Column="2" Grid.Row="5" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="2" Grid.Row="6" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="2" Grid.Row="7" Margin="2,1,2,1" Background="AliceBlue" />
        <TextBox Grid.Column="2" Grid.Row="8" Margin="2,1,2,1" Background="AliceBlue" />
        <TextBox Grid.Column="2" Grid.Row="9" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="2" Grid.Row="10" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="2" Grid.Row="11" Margin="2,1,2,1" Background="GreenYellow" />
        <TextBox Grid.Column="2" Grid.Row="12" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="2" Grid.Row="13" Margin="2,1,2,1" Background="AliceBlue"/>
        <TextBox Grid.Column="2" Grid.Row="14" Margin="2,1,2,1" Background="GreenYellow" />
        <Slider x:Name="sl" Grid.Column="0" Grid.Row="15" ValueChanged="sl_ValueChanged" Value="0.5"  Minimum="0.1" Maximum="1"></Slider>
       
    </Grid>

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            List<string> ListLX=new List<string>();
            ListLX.Add("一般纳税人");
            ListLX.Add("小规模纳税人");

            QYLX.ItemsSource = ListLX;
            QYLX.SelectedIndex = 1;

        }
       
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            decimal d =0;
            if (decimal.TryParse(tb1.Text, out d) == false)
            {
                System.Windows.MessageBox.Show("您输入的数字不合法!必须是数字.");
            }

            if (d > 1000)
            {
                System.Windows.MessageBox.Show("您输入的数字过大,不可大于1000.");
            }
        }


 

posted @ 2008-12-08 16:45  昕友软件开发  阅读(307)  评论(0编辑  收藏  举报
欢迎访问我的开源项目:xyIM企业即时通讯