4天玩转wp7的第二天作业

主要的一些代码:

using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;

namespace WindowsPhoneApplication1
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void oKButton_Click(object sender, RoutedEventArgs e)
        {
            Agent newAgent = new Agent();
            newAgent.AgentName = agent.Text.Trim ();         //textBlock里面的内容一般要去除空格trim();
            newAgent.IsUndercover = undercoverCheckBox.IsChecked;
            if (ciaRadioButton.IsChecked == true)
            {
                newAgent.Agency = "cia";
            }
            else if (mi6RadioButton.IsChecked == true)
            {
                newAgent.Agency = "mi6";
            }
            else
                newAgent.Agency = "nsa";

            ListBoxItem lbi = (ListBoxItem)ProficinciesListBox.SelectedItem;  //为什么不能直接将selectedItem转换成string类型呢?
            newAgent.Proficiency = (string)lbi.Content;

            newAgent.RecordCreateDateTime = DateTime.Now;

            newAgent.Save();

            agent.Text = "";
            undercoverCheckBox.IsChecked = false;
            ciaRadioButton.IsChecked = false;
            mi6RadioButton.IsChecked = false;
            nsaRadioButton.IsChecked = false;
            ProficinciesListBox.SelectedItem = null;

 

        }
    }
}

创建的Agent类:

using System;

namespace WindowsPhoneApplication1
{
    public class Agent
    {
        public string  AgentName { get; set; }
        public string  Agency { get; set; }
        public bool?  IsUndercover { get; set; }    //bool类型后面加一个?表示只可以为null
        public string  Proficiency { get; set; }
        public DateTime  RecordCreateDateTime { get; set; } 

        public void Save()
        {
                     //此处省略。。。
        }
    }
}

 

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions >
                <RowDefinition Height="70"/>
                <RowDefinition Height="70"/>
                <RowDefinition Height="70"/>
                <RowDefinition Height="70"/>
                <RowDefinition Height="70"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="110"/>
               
            </Grid.RowDefinitions>
           
            <Grid.ColumnDefinitions >
                <ColumnDefinition Width="170"/>
                <ColumnDefinition Width="10"/>
                <ColumnDefinition Width="250"/>
            </Grid.ColumnDefinitions>
           
            <TextBlock Name="TextBlock1"
                       Text="agent code name?"
                       Grid.Row="0"
                       Grid.Column="0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch" />
            <TextBlock Name="TextBlock2"
                       Text="Is Undercover?"
                       Grid.Row="1"
                       Grid.Column="0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch" />
            <TextBlock Name="TextBlock3"
                       Text="agency?"
                       Grid.Row="2"
                       Grid.Column="0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch" />
            <TextBlock Name="TextBlock4"
                       Text="Proficincies"
                       Grid.Row="5"
                       Grid.Column="0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch" />
           
            <TextBox Name="agent"
                     Grid.Row="0"
                     Grid.Column="2"
                     HorizontalAlignment="stretch"
                     VerticalAlignment="Stretch"  />
           
            <CheckBox Name="undercoverCheckBox"
                      Grid.Row="1"
                      Grid.Column="2"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch" />
           
            <RadioButton Name="ciaRadioButton"
                         Content="cia"
                         Grid.Row="2"
                         Grid.Column="2"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Stretch"
                         GroupName="agencyGroup"/>
            <RadioButton Name="mi6RadioButton"
                         Content="mi6"
                         Grid.Row="3"
                         Grid.Column="2"
                         VerticalAlignment="Stretch"
                         HorizontalAlignment="Stretch"
                         GroupName="agencyGroup"/>
          
            <RadioButton Name="nsaRadioButton"
                         Content="nsa"
                         Grid.Row="4"
                         Grid.Column="2"
                         VerticalAlignment="Stretch"
                         HorizontalAlignment="Stretch"
                         GroupName="agencyGroup"/>

            <ListBox Name="ProficinciesListBox"
                     Grid.Row="6"
                     Grid.Column="0"
                     Grid.ColumnSpan="3">
                     <ListBoxItem  Content="ewq"/>
                     <ListBoxItem  Content="qwte"/>
                     <ListBoxItem  Content="ytej"/>
                     <ListBoxItem  Content="gh"/>
               
                </ListBox>
           
            <Button Name="oKButton"
                    Grid.Row="6"
                    Grid.Column="2"
                 
                    Content="OK"
                    Click="oKButton_Click"/>
            
    </Grid>
    </Grid>

posted on 2012-03-10 18:48  tofq  阅读(142)  评论(0编辑  收藏  举报

导航