Silverlight 简单布局

效果:

Silverlight 简单布局

MainPage.xaml:

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="SilverlightApplication2.MainPage"

    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"

    d:DesignHeight="300" d:DesignWidth="400">



    <Grid x:Name="LayoutRoot" Background="Azure" ShowGridLines="True">

        <Grid.RowDefinitions>

            <RowDefinition Height="Auto"></RowDefinition>

            <RowDefinition Height="Auto" MinHeight="220"></RowDefinition>

            <RowDefinition Height="Auto" ></RowDefinition>

        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="Auto"></ColumnDefinition>

            <ColumnDefinition Width="*"></ColumnDefinition>

        </Grid.ColumnDefinitions>

        <TextBlock  Text="Name:" Grid.Row="0" Grid.Column="0" Margin="10,5,10,5"></TextBlock>

        <TextBlock x:Name="date1" Text="Date:" Grid.Row="1" Grid.Column="0" Margin="10,5,10,5"></TextBlock>

        <TextBlock x:Name="Mess" Text="Messatge:" FontSize="20" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10,5,10,5" ></TextBlock>

        <TextBox x:Name="name1" Text="Your Name" Grid.Row="0" Grid.Column="1" Width="150" HorizontalAlignment="Left" Margin="0,5,0,5">

        </TextBox>

        <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical">

            <sdk:Calendar x:Name="cal" SelectionMode="SingleDate" HorizontalAlignment="Left" Margin="0,5,0,5"></sdk:Calendar>

            <Button Click="OKButton_Click" x:Name="OKButton" Width="75" Height="25" HorizontalAlignment="Left" Content="OK" Margin="0,5,0,5"></Button>

        </StackPanel>



    </Grid>

</UserControl>

MainPage.xaml.cs 中的Button事件:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;



namespace SilverlightApplication2

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

        }



        private void OKButton_Click(object sender, RoutedEventArgs e)

        {

            string dateString;

            if (cal.SelectedDate == null)

            {

                dateString = "<Date not Selected>";

            }

            else

            {

                

                dateString = cal.SelectedDate.ToString();

            }

            Mess.Text = "Hi " + name1.Text.ToString() + "\n" + "Selected Date:" + dateString;

        }

    }

}

 

 

你可能感兴趣的:(silverlight)