Caliburn.Micro for wp7 学习笔记(2) : 响应 Butto事件

在上一个文章中我们创建了一个基于 Caliburn.Micro 框架的 wp7 程序

这章我们将来学习 Caliburn.Micro 框架下 的事件响应

一般第一个例子都是Hello, World 所以设想是这样的,页面上有一个按钮,我们点击按钮弹出一个MessageBox 显示 "Hello  World"

现在打开我们建立的工程

将MainPage.xaml 页面中的 controls:Panorama  删除

剩下个干净的页面,然后从工具箱拖出一个button

现在你的代码应该像这样

<phone:PhoneApplicationPage 
    x:Class="WP7App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">
   
    <Grid x:Name="LayoutRoot" Background="Transparent">
  
        <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="128,308,0,0" Name="button1" VerticalAlignment="Top" Width="160" />
    
    </Grid>
  
</phone:PhoneApplicationPage>

 

然后打开ViewModels 目录下的 MainPageViewModel.cs

在里面添加如下代码

        public void button1()
        {

            MessageBox.Show("Hello  World");

        }

然后运行 ,点击Button按钮,你的程序现在应该如下显示

 

 很简便吧,下一个文章我将分析下它的原理

posted @ 2012-05-10 16:29  iiixxxiii  阅读(387)  评论(0编辑  收藏  举报