wp7发送短信

    <!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <!--TitlePanel 包含应用程序的名称和页标题-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="发送短信" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>


        <!--ContentPanel - 在此处放置其他内容-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock Height="40" HorizontalAlignment="Left" Margin="25,16,0,0" Name="textBlock1" Text="接收者:" VerticalAlignment="Top" FontSize="30" Width="144" />
            <TextBox Height="72" HorizontalAlignment="Left" Margin="12,62,0,0" Name="txtPhoneNumber" Text="" VerticalAlignment="Top" Width="444" >
                <TextBox.InputScope>
                    <InputScope>
                        <InputScopeName NameValue="Number"/>
                    </InputScope>
                </TextBox.InputScope>
            </TextBox>
            <TextBlock TextWrapping="Wrap" FontSize="30" Height="177" HorizontalAlignment="Left" Margin="6,270,0,0" Name="textBlock2" Text="短信内容" VerticalAlignment="Top" Width="46" />
            <TextBox Height="406" HorizontalAlignment="Left" Margin="48,140,0,0" Name="txtMessage" Text="" VerticalAlignment="Top" Width="382" TextWrapping="Wrap" />
            <Button Content="发送" Height="79" HorizontalAlignment="Left" Margin="-12,538,0,0" Name="btnSend" VerticalAlignment="Top" Width="480" Click="btnSend_Click" />
            <Button Content="选择电话号码" Height="69" HorizontalAlignment="Left" Margin="210,0,0,0" Name="btnChoose" VerticalAlignment="Top" Width="220" Click="btnChoose_Click" />
        </Grid>

    </Grid>


后台代码:

        PhoneNumberChooserTask myChooser = new PhoneNumberChooserTask();
        SmsComposeTask SMS = null;


        // 构造函数  
        public MainPage()
        {
            InitializeComponent();
            // 实例化  
            SMS = new SmsComposeTask();
            // 注册回调事件  
            myChooser.Completed += (sender, e) =>
            {
                if (e.TaskResult == TaskResult.OK)
                {
                    Dispatcher.BeginInvoke(() => { this.txtPhoneNumber.Text = e.PhoneNumber; });
                }
            };
        }


        // 选择联系人  
        private void btnChoose_Click(object sender, RoutedEventArgs e)
        {
            if (myChooser == null)
            {
                myChooser = new PhoneNumberChooserTask();
            }
            myChooser.Show();
        }


        // 发送  
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            if (txtPhoneNumber.Text == "" || txtMessage.Text == "")
            {
                MessageBox.Show("接收号码和短信内容不能为空。");
                return;
            }
            if (SMS == null)
            {
                SMS = new SmsComposeTask();
            }
            // 赋值  
            SMS.To = txtPhoneNumber.Text;
            SMS.Body = txtMessage.Text;


            try
            {
                SMS.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值