微软在WP上的发展从原来的Win7到Win8,Win8.1,到现在的Win10 UWP,什么是UWP,UWP即Windows 10 中的Universal Windows Platform简称。即Windows通用应用平台,在Win 10 Mobile/Surface(Windows平板电脑)/PC/Xbox/HoloLens等平台上运行,uwp不同于传统pc上的exe应用也跟只适用于手机端的app有本质区别。它并不是为某一个终端而设计,而是可以在所有windows10设备上运行。
简单的说,uwp就是通用应用的意思可以在电脑端,手机端,或其他设备通用。不用分别为不同的平台设计不同的软件。即一个软件就可以通吃。这估计现在是win10系统的一个软件发展趋势了。不管是开发者,还是使用者,都省事。
废话不多说,科普完了,直接进入正题,先给大家看一下效果图,主要是功能简单地实现了,界面有点丑QAQ
开发工具环境:
VS2015 Update2+Win10
话说15 Update的包好大7个G左右,安装下来大概有40个G左右,不过VS15用着还是挺有新鲜感的,还有很多新的语法糖,安装后会有一个Wp的虚拟机,这个虚拟机还对硬件是有要求的,好像是硬件虚拟2级内存什么的,我记得不是太清楚了,系统还是Win10最好,调试的话有Wp真机的话更好,没有的就只能就模拟器了,不过话说,微软和Xamarinn收购以后,模拟器还是挺好用的
这里我给出官方下载地址 https://developer.microsoft.com/zh-cn/windows/downloads
1,新建项目,C# - windows - windows Phone空白应用程序
页面代码很简单,就是一个Grid里面包着几个控件
<Page
x:Class="App7.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App7"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="IndianRed">
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Bing 词典" Margin="0 30 0 0" FontSize="40" TextAlignment="Center"></TextBlock>
<TextBlock FontSize="14" Text="V1.0(暂时只能翻译英文)" Margin="125 80 0 0"></TextBlock>
<TextBox FontSize="30" TextAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Height="60" Background="White" x:Name="words"></TextBox>
<Button Grid.Row="2" FontSize="40" Width="350" Height="80" Foreground="White" Background="LightPink" HorizontalAlignment="Center" Content="G O" Click="Button_Click"></Button>
<TextBlock TextWrapping="Wrap" Grid.Row= "3" FontSize="30" x:Name="text"></TextBlock>
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Bottom" Grid.Row="3" Text="MicroSoft Bing" FontSize="30"></TextBlock>
</Grid>
</Page>
这其实跟我们的Html页面差不多,他这个使用的是XAML语法,X:Name就是给控件取个名字,后台代码如下
private async void Button_Click(object sender, RoutedEventArgs e)
{
string cc = words.Text.Trim();
if (cc.Length==0)
{
return;
}
string url = &q