hahacjh
既然选择了远方 便只顾风雨兼程

<Grid x:Name="counterPanel" Background="AliceBlue">

</Grid>

 

代码

public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
Loaded
+= new RoutedEventHandler(Page_Loaded);
}

void Page_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer timer
= new DispatcherTimer();
int counter = 0;

counterPanel.MouseLeftButtonDown
+=
delegate(object s, MouseButtonEventArgs args)
{
if (timer.IsEnabled) timer.Stop(); else timer.Start();
};

timer.Tick
+=
delegate(object s, EventArgs args)
{
counterPanel.Children.Clear();
counterPanel.Children.Add(
new TextBlock
{
Text
= counter++.ToString(),
Width
=200,
Height
=100,
FontSize
=36
});
};

timer.Interval
= new TimeSpan(0, 0, 1); // one second
timer.Start();

}
}

 

 

 

 

 

 

posted on 2010-03-01 14:49  hahacjh  阅读(225)  评论(0编辑  收藏  举报