CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { });
Thứ Sáu, 13 tháng 2, 2015
Chạy trong UI thread window phone store app
Thứ Năm, 12 tháng 2, 2015
Các link hướng dẫn custom button , control
http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-textbox
http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-textbox
http://nirmitk26.blogspot.com/2011/02/round-button-in-windows-phone-7.html
http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-textbox
http://nirmitk26.blogspot.com/2011/02/round-button-in-windows-phone-7.html
Thứ Sáu, 6 tháng 2, 2015
Tương tác dropbox trong window phone
_ Download thư viện dropnet:http://dkdevelopment.net/what-im-doing/dropnet/
_ Lấy api key và api secret
_ Code file mainpage.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using BBDropbox.Resources;
using Windows.Security.Authentication.Web;
using DropNet;
using DropNet.Models;
using System.IO.IsolatedStorage;
using System.IO;
using System.Diagnostics;
namespace BBDropbox
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
DropNetClient _client = new DropNetClient("l395hahs18o5uab", "sazu6n8axbfol5f");
private static string FileName = "accessToken.xml";
UserLogin userlogin = new UserLogin();
public MainPage()
{
InitializeComponent();
_client.UseSandbox = false;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
webAuth.Navigate(new Uri("http://google.com", UriKind.Absolute));
}
public void CheckAuthentication(Uri uri)
{
if (uri.LocalPath == "/1/oauth/authorize_submit")
{
_client.GetAccessTokenAsync((accessToken) =>
{
var item = accessToken;
_client.UserLogin = new UserLogin { Token = accessToken.Token, Secret = accessToken.Secret };
_client.AccountInfoAsync((success) => {
var ed = success;
},
(error) => {
});
_client.CreateFolderAsync("/NewFolder1",
(metaData) =>
{
//Do something with metaData
var item1 = metaData;
},
(error) =>
{
//Do something on error
});
},
(error) =>
{
MessageBox.Show(error.ToString());
});
}
}
private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
{
CheckAuthentication(e.Uri);
}
private void SaveAccessTokenToIsolatedStorage(UserLogin user)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(FileName, FileMode.Create, FileAccess.Write, store))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.WriteLine(user.Token+"|"+user.Secret);
Console.WriteLine("You have written to the file.");
}
}
}
}
private UserLogin LoadAccessTokenFromIsolatedStorage()
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream =
new IsolatedStorageFileStream(FileName, FileMode.OpenOrCreate, FileAccess.Read, store))
{
using (StreamReader reader = new StreamReader(stream))
{
String value = reader.ReadToEnd();
Debug.WriteLine(value);
char[] seperator = new char[1] {'|'};
String token = value.Split(seperator).ElementAt(0);
String secret = value.Split(seperator).ElementAt(1);
userlogin.Token = token;
userlogin.Secret = secret;
Debug.WriteLine("token ne:" + token + "|" + secret);
}
}
}
return null;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// Async
_client.GetTokenAsync((userLogin) =>
{
var url = _client.BuildAuthorizeUrl();
webAuth.Navigate(new Uri(url, UriKind.Absolute));
},
(error) =>
{
//Handle error
});
}
private void Button_Click1(object sender, RoutedEventArgs e)
{
SaveAccessTokenToIsolatedStorage(new UserLogin { Token = "0rxf8910ixcc7hs7", Secret = "2f49my2nh7fohdy" });
LoadAccessTokenFromIsolatedStorage();
/*
_client.UserLogin = new UserLogin { Token = "0rxf8910ixcc7hs7", Secret = "2f49my2nh7fohdy" };
_client.AccountInfoAsync((success) =>
{
var ed = success;
},
(error) =>
{
});
_client.DeleteAsync("/unnamed (1).png",
(response) =>
{
//Do something
},
(error) =>
{
//Do something on error
});
_client.CreateFolderAsync("/NewFolder1",
(metaData) =>
{
//Do something with metaData
var item1 = metaData;
},
(error) =>
{
//Do something on error
});
*/
}
}
}
_ Code file xaml:
<phone:PhoneApplicationPage
x:Class="BBDropbox.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- LOCALIZATION NOTE:
To localize the displayed strings copy their values to appropriately named
keys in the app's neutral language resource file (AppResources.resx) then
replace the hard-coded text value between the attributes' quotation marks
with the binding clause whose path points to that string name.
For example:
Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
This binding points to the template's string resource named "ApplicationTitle".
Adding supported languages in the Project Properties tab will create a
new resx file per language that can carry the translated values of your
UI strings. The binding in these examples will cause the value of the
attributes to be drawn from the .resx file that matches the
CurrentUICulture of the app at run time.
-->
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<Button Content="checkNotLogin" Click="Button_Click1"></Button>
<Button Content="checkLogin" Click="Button_Click"></Button>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser Name="webAuth" Navigated="WebBrowser_Navigated" IsScriptEnabled="True" />
</Grid>
<!--Uncomment to see an alignment grid to help ensure your controls are
aligned on common boundaries. The image has a top margin of -32px to
account for the System Tray. Set this to 0 (or remove the margin altogether)
if the System Tray is hidden.
Before shipping remove this XAML and the image itself.-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
</Grid>
</phone:PhoneApplicationPage>
_ Lấy api key và api secret
_ Code file mainpage.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using BBDropbox.Resources;
using Windows.Security.Authentication.Web;
using DropNet;
using DropNet.Models;
using System.IO.IsolatedStorage;
using System.IO;
using System.Diagnostics;
namespace BBDropbox
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
DropNetClient _client = new DropNetClient("l395hahs18o5uab", "sazu6n8axbfol5f");
private static string FileName = "accessToken.xml";
UserLogin userlogin = new UserLogin();
public MainPage()
{
InitializeComponent();
_client.UseSandbox = false;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
webAuth.Navigate(new Uri("http://google.com", UriKind.Absolute));
}
public void CheckAuthentication(Uri uri)
{
if (uri.LocalPath == "/1/oauth/authorize_submit")
{
_client.GetAccessTokenAsync((accessToken) =>
{
var item = accessToken;
_client.UserLogin = new UserLogin { Token = accessToken.Token, Secret = accessToken.Secret };
_client.AccountInfoAsync((success) => {
var ed = success;
},
(error) => {
});
_client.CreateFolderAsync("/NewFolder1",
(metaData) =>
{
//Do something with metaData
var item1 = metaData;
},
(error) =>
{
//Do something on error
});
},
(error) =>
{
MessageBox.Show(error.ToString());
});
}
}
private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
{
CheckAuthentication(e.Uri);
}
private void SaveAccessTokenToIsolatedStorage(UserLogin user)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(FileName, FileMode.Create, FileAccess.Write, store))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.WriteLine(user.Token+"|"+user.Secret);
Console.WriteLine("You have written to the file.");
}
}
}
}
private UserLogin LoadAccessTokenFromIsolatedStorage()
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream =
new IsolatedStorageFileStream(FileName, FileMode.OpenOrCreate, FileAccess.Read, store))
{
using (StreamReader reader = new StreamReader(stream))
{
String value = reader.ReadToEnd();
Debug.WriteLine(value);
char[] seperator = new char[1] {'|'};
String token = value.Split(seperator).ElementAt(0);
String secret = value.Split(seperator).ElementAt(1);
userlogin.Token = token;
userlogin.Secret = secret;
Debug.WriteLine("token ne:" + token + "|" + secret);
}
}
}
return null;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// Async
_client.GetTokenAsync((userLogin) =>
{
var url = _client.BuildAuthorizeUrl();
webAuth.Navigate(new Uri(url, UriKind.Absolute));
},
(error) =>
{
//Handle error
});
}
private void Button_Click1(object sender, RoutedEventArgs e)
{
SaveAccessTokenToIsolatedStorage(new UserLogin { Token = "0rxf8910ixcc7hs7", Secret = "2f49my2nh7fohdy" });
LoadAccessTokenFromIsolatedStorage();
/*
_client.UserLogin = new UserLogin { Token = "0rxf8910ixcc7hs7", Secret = "2f49my2nh7fohdy" };
_client.AccountInfoAsync((success) =>
{
var ed = success;
},
(error) =>
{
});
_client.DeleteAsync("/unnamed (1).png",
(response) =>
{
//Do something
},
(error) =>
{
//Do something on error
});
_client.CreateFolderAsync("/NewFolder1",
(metaData) =>
{
//Do something with metaData
var item1 = metaData;
},
(error) =>
{
//Do something on error
});
*/
}
}
}
_ Code file xaml:
<phone:PhoneApplicationPage
x:Class="BBDropbox.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- LOCALIZATION NOTE:
To localize the displayed strings copy their values to appropriately named
keys in the app's neutral language resource file (AppResources.resx) then
replace the hard-coded text value between the attributes' quotation marks
with the binding clause whose path points to that string name.
For example:
Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
This binding points to the template's string resource named "ApplicationTitle".
Adding supported languages in the Project Properties tab will create a
new resx file per language that can carry the translated values of your
UI strings. The binding in these examples will cause the value of the
attributes to be drawn from the .resx file that matches the
CurrentUICulture of the app at run time.
-->
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<Button Content="checkNotLogin" Click="Button_Click1"></Button>
<Button Content="checkLogin" Click="Button_Click"></Button>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser Name="webAuth" Navigated="WebBrowser_Navigated" IsScriptEnabled="True" />
</Grid>
<!--Uncomment to see an alignment grid to help ensure your controls are
aligned on common boundaries. The image has a top margin of -32px to
account for the System Tray. Set this to 0 (or remove the margin altogether)
if the System Tray is hidden.
Before shipping remove this XAML and the image itself.-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
</Grid>
</phone:PhoneApplicationPage>
Thứ Sáu, 16 tháng 1, 2015
Dùng SQLite trong window phone
Đây là các bài hướng dẫn chi tiết cách làm:
http://stackoverflow.com/questions/23195044/wp8-sqlite-error-the-specified-module-could-not-be-found
http://wp.qmatteoq.com/working-with-sqlite-in-windows-phone-8-a-sqlite-net-version-for-mobile/
http://developer.nokia.com/community/wiki/How_to_use_SQLite_in_Windows_Phone
http://blogs.msdn.com/b/pakistan/archive/2014/04/23/using-sqlite-with-windows-phone-8.aspx
Đặc biệt chú ý muốn có thư viện SQLite for window phone mình phải download về tại http://sqlite.org/download.html . Nơi có thư viện compiled trước cho window phone .
Đây là link thư viện đã thử thành công : http://www.sqlite.org/2013/sqlite-wp80-winrt-3080000.vsix
Đây là thư viện đã dùng thử nhưng nó ko tạo sdk cho mình: https://visualstudiogallery.msdn.microsoft.com/cd120b42-30f4-446e-8287-45387a4f40b7
http://stackoverflow.com/questions/23195044/wp8-sqlite-error-the-specified-module-could-not-be-found
http://wp.qmatteoq.com/working-with-sqlite-in-windows-phone-8-a-sqlite-net-version-for-mobile/
http://developer.nokia.com/community/wiki/How_to_use_SQLite_in_Windows_Phone
http://blogs.msdn.com/b/pakistan/archive/2014/04/23/using-sqlite-with-windows-phone-8.aspx
Đặc biệt chú ý muốn có thư viện SQLite for window phone mình phải download về tại http://sqlite.org/download.html . Nơi có thư viện compiled trước cho window phone .
Đây là link thư viện đã thử thành công : http://www.sqlite.org/2013/sqlite-wp80-winrt-3080000.vsix
Đây là thư viện đã dùng thử nhưng nó ko tạo sdk cho mình: https://visualstudiogallery.msdn.microsoft.com/cd120b42-30f4-446e-8287-45387a4f40b7
Thứ Năm, 1 tháng 1, 2015
Save ảnh từ application to IsolatedStorage ,read from IsolatedStorage ,Save to Media library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Resources;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Tasks;
namespace WP7SampleProject40
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
// Create a filename for JPEG file in isolated storage.
String tempJPEG = "logo.jpg";
// Create virtual store and file stream. Check for duplicate tempJPEG files.
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(tempJPEG))
{
myIsolatedStorage.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
StreamResourceInfo sri = null;
Uri uri = new Uri(tempJPEG, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
//wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
}
private void btnRead_Click(object sender, RoutedEventArgs e)
{
BitmapImage bi = new BitmapImage();
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
{
bi.SetSource(fileStream);
this.img.Height = bi.PixelHeight;
this.img.Width = bi.PixelWidth;
}
}
this.img.Source = bi;
}
private void btnMedia_Click(object sender, RoutedEventArgs e)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
{
MediaLibrary mediaLibrary = new MediaLibrary();
Picture pic = mediaLibrary.SavePicture("SavedLogo.jpg", fileStream);
fileStream.Close();
}
}
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Show();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Resources;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Tasks;
namespace WP7SampleProject40
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
// Create a filename for JPEG file in isolated storage.
String tempJPEG = "logo.jpg";
// Create virtual store and file stream. Check for duplicate tempJPEG files.
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(tempJPEG))
{
myIsolatedStorage.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
StreamResourceInfo sri = null;
Uri uri = new Uri(tempJPEG, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
//wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
}
private void btnRead_Click(object sender, RoutedEventArgs e)
{
BitmapImage bi = new BitmapImage();
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
{
bi.SetSource(fileStream);
this.img.Height = bi.PixelHeight;
this.img.Width = bi.PixelWidth;
}
}
this.img.Source = bi;
}
private void btnMedia_Click(object sender, RoutedEventArgs e)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
{
MediaLibrary mediaLibrary = new MediaLibrary();
Picture pic = mediaLibrary.SavePicture("SavedLogo.jpg", fileStream);
fileStream.Close();
}
}
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Show();
}
}
}
Đăng ký:
Bài đăng (Atom)