Silverlight学习起步
XAML代码
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class="HelloWorld.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="Beige">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="300*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="210*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10"
x:Name="textBlock1" Text="First Name" VerticalAlignment="Top"/>
<TextBlock Grid.Row="1" Height="23" HorizontalAlignment="Left"
Margin="10" x:Name="textBlock2" Text="Date:" VerticalAlignment="Top"/>
<TextBox Grid.Column="1" Height="23" Margin="0,10,194,0" x:Name="name1"
VerticalAlignment="Top" Text="Your Name"/>
<StackPanel Grid.Column="1" Grid.Row="1" x:Name="staticPanel1" >
<controls:Calendar x:Name="cal1" HorizontalAlignment="Left">
</controls:Calendar>
<TextBlock Height="Auto" Name="message1" Text="Message:" FontSize="29">
</TextBlock>
<Button Content="OK" Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left"
Margin="0,10" Name="okButton" VerticalAlignment="Top" Width="75"></Button>
</StackPanel>
</Grid>
</UserControl>
C#代码:
1 using System;
2 using System.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Documents;
5 using System.Windows.Ink;
6 using System.Windows.Input;
7 using System.Windows.Media;
8 using System.Windows.Media.Animation;
9 using System.Windows.Shapes;
10
11 namespace HelloWorld
12 {
13 public partial class MainPage : UserControl
14 {
15 public MainPage()
16 {
17 // 为初始化变量所必需
18 InitializeComponent();
19 this.okButton.Click += new RoutedEventHandler(okButton_Click);
20 }
21
22 void okButton_Click(object sender, RoutedEventArgs e)
23 {
24 string dateString;
25 if(cal1.SelectedDate==null)
26 {
27 dateString = "没有选中日期";
28 }
29 else
30 {
31 dateString = cal1.SelectedDate.ToString();
32 }
33 message1.Text = "Hi" + name1.Text + "\n" + "选择的日期是:" + dateString;
34 }
35 }
36 }
敏于事,慎于言