(TitleId,DiaplayName,args,LogoUri,size);
Obj.VisualElements.ShowNameOnSquare150x150Logo = true;
if (await Obj.RequestCreateAsync())
{
await new MessageDialog("OK").ShowAsync();
}
}
删除,修改磁贴
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
//磁贴的唯一标识
string TitleId = "My_Title";
var Title = new SecondaryTile(TitleId);
Title.VisualElements.ShowNameOnSquare150x150Logo = false;
await Title.RequestDeleteAsync();
}
磁贴通知
var toast = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
var textNodes = toast.GetElementsByTagName("text");
textNodes\[0\].InnerText = "呵呵呵";
textNodes\[1\].InnerText = "你是猴子请来的救兵吗?";
textNodes\[2\].InnerText = "呵呵呵";
var Message = new TileNotification(toast);
TileUpdateManager.CreateTileUpdaterForSecondaryTile("My\_Title").Update(Message);
HttpClient
string url = "http://www.baidu.com";
HttpClient client = new HttpClient();
string responce = await client.GetStringAsync(url);
Weather天气实战
利用GPS获取手机坐标(经纬度)
var geo = new Geolocator();
var P = await geo.GetGeopositionAsync();
var Po = P.Coordinate.Point.Position;
百度地图API获取位置信息
string AppId = "XTTNdkZYIFCIqKVW1vfYUID3eWOgizwC";
string Type = "json";
string Url = "http://api.map.baidu.com/geocoder/v2/?ak=" + AppId + "&location=" + Po.Latitude + "," + Po.Longitude + "&output=" + Type + "";
HttpClient client = new HttpClient();
var json = await client.GetStringAsync(Url);
JsonObject jsonRes = JsonObject.Parse(json);
var City = jsonRes.GetNamedObject("result").GetNamedObject("addressComponent").GetNamedString("city");
百度天气接口 获取天气信息
string WeaApi = "http://api.map.baidu.com/telematics/v3/weather?location=" + City + "&output=json&ak=" + AppId;
var WeatherJson = await client.GetStringAsync(WeaApi);
Info i= JsonConvert.DeserializeObject<Info>(WeatherJson);
this.DataContext = i;
天气信息 Info Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Weather
{
public class Info
{
public int error { get; set; }
public string status { get; set; }
public string date { get; set; }
public List
}
public class result
{
public string currentCity { get; set; }
public string pm25 { get; set; }
public IList<indexitem> index { get; set; }
public IList<weather\_data\_item> weather\_data { get; set; }
}
public struct weather\_data\_item
{
public string date { get; set; }
public string dayPictureUrl { get; set; }
public string nightPictureUrl { get; set; }
public string weather { get; set; }
public string wind { get; set; }
public string temperature { get; set; }
}
public struct indexitem
{
public string title { get; set; }
public string zs { get; set; }
public string tipt { get; set; }
public string des { get; set; }
}
}
前台Xmal代码绑定
<Grid>
<Grid.Background>
<ImageBrush ImageSource="ms-appx:///Assets/zhuo.jpeg"/>
</Grid.Background>
<ProgressRing x:Name="gif"></ProgressRing>
<Hub Header="Weather">
<HubSection>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding results\[0\].currentCity}" FontSize="60"></TextBlock>
<TextBlock Text="{Binding results\[0\].pm25}" FontSize="30"></TextBlock>
</StackPanel>
</DataTemplate>
</HubSection>
<HubSection>
<DataTemplate>
<ListView ItemsSource="{Binding results\[0\].weather\_data}">
<ListView.ItemTemplate>
<DataTemplate>
<Border Width="360" BorderThickness="2" BorderBrush="Green">
<StackPanel>
<TextBlock Text="{Binding date}" FontSize="25"></TextBlock>
<TextBlock Text="{Binding weather}" FontSize="30"></TextBlock>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding dayPictureUrl}" Stretch="Uniform" Width="60" Height="60"></Image>
</StackPanel>
<TextBlock Text="{Binding wind}" FontSize="25"></TextBlock>
<TextBlock Text="{Binding temperature}" FontSize="30"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</HubSection>
<HubSection>
<DataTemplate>
<ListView ItemsSource="{Binding results\[0\].index}">
<ListView.ItemTemplate>
<DataTemplate>
<Border>
<StackPanel>
<TextBlock Text="{Binding tipt}" FontSize="25" Foreground="#FF2996AE"></TextBlock>
<TextBlock Text="{Binding zs}" FontSize="30" Foreground="Green"></TextBlock>
<TextBlock Text="{Binding des}" FontSize="20" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</HubSection>
</Hub>
</Grid>
天气数据加载时用ProgressRing控制
加载前
Pro.IsActive=True;
加载完毕
Pro.IsActive=false;
数据绑定
public class User
{
public string Name { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: 准备此处显示的页面。
// TODO: 如果您的应用程序包含多个页面,请确保
// 通过注册以下事件来处理硬件“后退”按钮:
// Windows.Phone.UI.Input.HardwareButtons.BackPressed 事件。
// 如果使用由某些模板提供的 NavigationHelper,
// 则系统会为您处理该事件。
User U = new User();
U.Name = "张三";
U.Phone = "1888";
U.Address = "东北";
this.DataContext = U;
}
<TextBox Text="{Binding }"></TextBox>
<TextBox Text="{Binding Name}"></TextBox>
<TextBox Text="{Binding Address}"></TextBox>
UWP汉堡包菜单
Xaml:
<AppBarButton Click="Button\_Click" Height="50" Width="50">
<SymbolIcon Symbol="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</AppBarButton>
<SplitView x:Name="mySplit" DisplayMode="CompactOverlay" CompactPaneLength="0"
OpenPaneLength="200" IsPaneOpen="False" >
<SplitView.Pane>
<StackPanel Background="Pink">
<AppBarButton Click="Button\_Click" Height="50" Width="50">
<SymbolIcon Symbol="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</AppBarButton>
<TextBlock FontSize="20">第一项</TextBlock>
<TextBlock FontSize="20">第二项</TextBlock>
<TextBlock FontSize="20">第一项</TextBlock>
<TextBlock FontSize="20">第二项</TextBlock>
<TextBlock FontSize="20">第一项</TextBlock>
<TextBlock FontSize="20">第二项</TextBlock>
</StackPanel>
</SplitView.Pane>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center" FontSize="100">Spring
CS:
private void Button_Click(object sender, RoutedEventArgs e)
{
mySplit.IsPaneOpen = !mySplit.IsPaneOpen;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章