Skip to content

Instantly share code, notes, and snippets.

Windows App Tutorials wtuts

Block or report user

Report or block wtuts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ToastService.cs
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));
View mainpage.xaml
<StackPanel Margin="12" VerticalAlignment="Center">
<TextBox x:Name="MyTextBox"/>
<Button Content="Toast" HorizontalAlignment="Stretch" Click="ButtonBase_OnClick"/>
</StackPanel>
View Save.cs
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;
View Thumbnail.cs
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();
View CopyToFolder.cs
public async void CopyFileToFolder(StorageFile filetoCopy, StorageFolder folder)
{
await filetoCopy.CopyAsync(folder);
}
View CopyFile.cs
public async void CopyFile(StorageFile fileToCopy,StorageFile filetoReplace)
{
await fileToCopy.CopyAndReplaceAsync(filetoReplace);
}
View Size.cs
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;
View Backbutton.cs
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)
View Backbutton.cs
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
}
View DatabaseHelper.cs
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;
You can’t perform that action at this time.