Skip to content

Instantly share code, notes, and snippets.

View wtuts's full-sized avatar

Windows App Tutorials wtuts

View GitHub Profile
public class ToastService
{
public static void ShowToastNotification(String message)
{
ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
// Set Text
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode(message));
<StackPanel Margin="12" VerticalAlignment="Center">
<TextBox x:Name="MyTextBox"/>
<Button Content="Toast" HorizontalAlignment="Stretch" Click="ButtonBase_OnClick"/>
</StackPanel>
public async void SaveThumbnail(StorageFile videofile, string thumbnailfilename)
{
var thumbnail = await videofile.GetThumbnailAsync(ThumbnailMode.VideosView);
var saveFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(thumbnailfilename, CreationCollisionOption.GenerateUniqueName);
var inputBuffer = new Windows.Storage.Streams.Buffer(2048);
using (var destFileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
{
IBuffer buf;
public async Task<BitmapImage> FetchThumbnail(StorageFile videofile)
{
//Fetching the thumbnail in form of StorageItemThumbnail
var thumbnail = await videofile.GetThumbnailAsync(ThumbnailMode.VideosView);
var inputBuffer = new Windows.Storage.Streams.Buffer(2048);
IBuffer buf;
IRandomAccessStream stream=new InMemoryRandomAccessStream();
public async void CopyFileToFolder(StorageFile filetoCopy, StorageFolder folder)
{
await filetoCopy.CopyAsync(folder);
}
public async void CopyFile(StorageFile fileToCopy,StorageFile filetoReplace)
{
await fileToCopy.CopyAndReplaceAsync(filetoReplace);
}
@wtuts
wtuts / Size.cs
Last active January 13, 2016 15:46
public async Task<string> GetFileSize(StorageFile file)
{
var basicProperties = await file.GetBasicPropertiesAsync();
var length = basicProperties.Size;
return Calculatesize(length);
}
public string Calculatesize(double sizeInBytes)
{
const double terabyte = 1099511627776;
BackKeyPress += OnBackKeyPress;
private void OnBackKeyPress(object sender, CancelEventArgs e)
{
//Code to disable the back button
e.Cancel = true;
//Here you can add your own code and perform any task
var mm = MessageBox.Show("Do you wish to exit the app", "Exit", MessageBoxButton.OKCancel);
if (mm == MessageBoxResult.OK)
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
//Code to disable the back button
e.Handled = true;
//Here you can add your own code and perfrom any task
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using SQLite;