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);
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构