- Create your DatePicker application described in this article or your own application.
- Insert in MainPage.xaml.cs
using System.Globalization; using System.Threading;
- Windows Phone supports the display languages you may find here
- Next code fragment do all you need (of course you must choose "Culture code" you need):
public MainPage() { CultureInfo newCulture = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentCulture = newCulture; Thread.CurrentThread.CurrentUICulture = newCulture; ... }
- But if your language not supported by windows phone?
public MainPage() { CultureInfo newCulture = new CultureInfo("en-GB"); //change format of DatePicker to you own format newCulture.DateTimeFormat.ShortDatePattern = "d/MMM/yyyy"; //set day names newCulture.DateTimeFormat.DayNames = new string[] { "first day", "second day", "third day", "4 day", "5 day", "6 day", "7 day" }; //set month names newCulture.DateTimeFormat.MonthNames = new string[] {"1 month", "2 month", "3 month", "4 month", "5 month", "6 month", "7 month", "8 month", "9 month", "10 month", "11 month", "12 month", ""}; Thread.CurrentThread.CurrentCulture = newCulture; Thread.CurrentThread.CurrentUICulture = newCulture; ... }
- Enjoy
WP7: How to Localize you DatePicker
SourceForge.net: Mouse Wheeling Ticker: SCM
SourceForge.net: Mouse Wheeling Ticker: SCM
Mouse Wheeling Ticker - ticker to scroll any content (in any browser) without much action which does not load the CPU and allows the mouse wheel to scroll. Enjoy :)
Mouse Wheeling Ticker - ticker to scroll any content (in any browser) without much action which does not load the CPU and allows the mouse wheel to scroll. Enjoy :)
Ярлыки:
JQuery plugin,
Mouse Wheeling Ticker,
scroller,
ticker
WP7 - Create DatePicker control programmatically
If you need use DatePicker in your windows phone application you must create control field in xaml file. Or no...
Let's create DatePicker control programmatically without any code in xaml file.
Let's create DatePicker control programmatically without any code in xaml file.
- Install Silverlight Toolkit last version.
- Create new "Windows Phone Application" named "DatePickerControlProgrammatically".
- Adding new reference to Microsoft.Phone.Controls.Toolkit
- Main Menu -> Project -> Add Reference -> Tab ".NET" -> choose Microsoft.Phone.Controls.Toolkit.
- If you no find Microsoft.Phone.Controls.Toolkit in ".NET" tab go to "Browse" tab and navigate to this dll in you computer (for me "C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Toolkit\Sep10\Bin\Microsoft.Phone.Controls.Toolkit.dll").
- Create new folder in project "Toolkit.Content" and put inside two images for cancel and check control (you can get them in Silverlight Toolkit project or create you own icons):
- Don't forget change "Build Action" property for each image to "Content" from "Resource".
- Override DatePicker class with our custom DatePickerCustom class. Create new class "DatePickerCustom.cs":
using System.Windows.Automation.Peers; using System.Windows.Automation.Provider; using System.Windows.Controls; using Microsoft.Phone.Controls; namespace DatePickerControlProgrammatically { public class DatePickerCustom : DatePicker { public void ClickTemplateButton() { Button btn = (GetTemplateChild("DateTimeButton") as Button); ButtonAutomationPeer peer = new ButtonAutomationPeer(btn); IInvokeProvider provider = (peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider); provider.Invoke(); } } }
- MainPage.xaml.cs - create new DatePickerCustom on Loaded event:
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; namespace DatePickerControlProgrammatically { public partial class MainPage : PhoneApplicationPage { private DatePickerCustom datePicker; // Constructor public MainPage() { InitializeComponent(); Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender, RoutedEventArgs e) { // create datePicker programmatically if (this.datePicker == null) { this.datePicker = new DatePickerCustom(); this.datePicker.IsTabStop = false; this.datePicker.MaxHeight = 0; this.datePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(datePicker_ValueChanged); LayoutRoot.Children.Add(this.datePicker); } } void datePicker_ValueChanged(object sender, DateTimeValueChangedEventArgs e) { // now we may use got value from datePicker PageTitle.Text = this.datePicker.ValueString; } } }
- For test add to MainPage.xaml two buttons - "Get Date" and "Clear Date":
<Button Content="Get Date" Height="72" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click"/> <Button Content="Clear Date" Height="72" HorizontalAlignment="Right" Name="button2" VerticalAlignment="Top" Width="160" Click="button2_Click"/>
- And to MainPage.xaml.cs add control for our buttons:
private void button1_Click(object sender, RoutedEventArgs e) { this.datePicker.ClickTemplateButton(); } private void button2_Click(object sender, RoutedEventArgs e) { PageTitle.Text = "Page Title"; clearDatePicker(); } void clearDatePicker() { this.datePicker.ValueChanged -= new EventHandler<DateTimeValueChangedEventArgs>(datePicker_ValueChanged); //this.datePicker.Value = "8/16/2011"; this.datePicker.Value = null; this.datePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(datePicker_ValueChanged); }
- Run
WP7 - Download zip file, unzip and save to isolated storage
- Create New "Windows Phone Application".
- Download "Silverlight SharpZipLib" from http://slsharpziplib.codeplex.com/releases/view/50561.
- Unpack "Silverlight SharpZipLib" and copy Bin/Release/SharpZipLib.WindowsPhone7.dll
- Create new folder "SharpZip" and past into copied SharpZipLib.WindowsPhone7.dll.
- Right click on project and "Add Reference...".
- Choose from "Browse" tab SharpZipLib.WindowsPhone7.dll from your project location.
- Add to "MainPage.xaml.cs" (probably you need to remove "using System.Windows.Shapes" because conflict System.Windows.Shapes.Path vs System.IO.Path):
using System.IO; using System.IO.IsolatedStorage; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
- Add code for download file from web:
public MainPage() { InitializeComponent(); Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender, RoutedEventArgs e) { System.Uri targetUri = new System.Uri("http://MyDomain/Archive.zip"); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri); //create asynchronous tast and declare callback to get data stream request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request); }
- And add function "ReadWebRequestCallback" to unzip & save file we got:
private void ReadWebRequestCallback(IAsyncResult callbackResult) { HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState; HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult); using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream())) { //open isolated storage to save files using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { using (ZipInputStream s = new ZipInputStream(httpwebStreamReader.BaseStream)) { //s.Password = "123456";//if archive is encrypted ZipEntry theEntry; try { while ((theEntry = s.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(theEntry.Name); string fileName = Path.GetFileName(theEntry.Name); // create directory if (directoryName.Length > 0) { Directory.CreateDirectory(directoryName); } if (fileName != String.Empty) { //save file to isolated storage using (BinaryWriter streamWriter = new BinaryWriter(new IsolatedStorageFileStream(theEntry.Name, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoStore))) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } } } } } catch (ZipException ze) { Debug.WriteLine(ze.Message); } } } } }
Run your application and enjoy.
Ярлыки:
download,
file,
IsolatedStorage,
SharpZipLib,
unzip,
Visual Studio,
windows phone 7,
wp7,
zip file
Subscribe to:
Posts (Atom)