How to get thumbnail of Video Storage File in Windows phone app

StorageFile class provides us with the method called GetThumbnailAsync with the help of which we can retrieve the thumbnail of a storage file in Windows phone app.

 

Important Note:
This method works only on the Storage Files that are stored in public directory of the phone. It doesn’t work on the files that are present in app data container or Local Storage of the app.

 

So the method discussed below will be useful when you need to fetch all the video files that are stored in the gallery of phone or you are working on video files picked with FileOpenPicker method.

 

The code for fetching the thumbnail of video storage file is as following

 

 

If you need to save the thumbnail image to the Local Storage of your app you can use the following code given below

 

 

I hope this post will be helpful to you.


 

How to copy one StorageFile into another StorageFile in Windows phone app using C#

StorageFile class provides a method called CopyAsync to copy the contents of one file into another.

The code for the above is as following

 

 

Note: In the given code above we replace the contents of filetoReplace by filetoCopy.

 

If you want to copy the file to a given StorageFolder you can use the CopyAsync method. The code for the following is given below

 

 


How to get the file size of Storage File in Windows phone app

StorageFile class provides different methods with the help of which we can retrieve the file size of a give StorageFile.

 

In the given function below we retrieve the file size of a given StorageFile using GetBasicPropertiesAsync() method. This method returns the basic properties of the given Storagefile in form of class object from which we can get the size of the given StorageFile.

 

 

Note:The property size of basicproperties object returns the file size in Ulong data type.

To convert the ulong type to proper file size in form of Bytes, Kilobytes or MB we have used the CalculateSize helper function.


How to disable Hardware Back button in Windows Phone App

Sometimes there may be a situation when you wish to prompt the user before exiting the page or frame of the application. So you need to control the back button function at that time.

Here is the code to disable the back button and perform your own function on pressing the back button.

 

Silverlight (Windows phone 8/8.1)

In the constructor of the page you need to add the following code as shown in the figure below

 


 

For example you wish to prompt the user before exiting the app then you can add the following code on your MainPage.

 

 

WinRT (Windows phone 8.1/10)

In the constructor of the page or frame you need to add the following code as shown in the figure below

 


 

 

I hope this post will be helpful to you


SQLite Database in Windows phone app – Part 3 (SQLite Exploration)

This is the third blog post of the series in which I am going to show you how to explore sqlite database stored in windows phone app.

If you have missed my last two blog posts you can refer to them from the links given below

 

SQLite Database in Windows phone app – Part 1 (Installation and Setup)

SQLite Database in Windows phone app – Part 2 (SQLite Operations)

 

Follow the steps given below

 

Step 1:
Download the IsoStoreSpy tool and SQLite Studio.

 

You can refer to the following blog post for downloading and setting up IsoStoreSpy tool.

http://windowsapptutorials.com/windows-phone/isolated-storage/how-to-access-isolated-or-local-storage-data-of-windows-phone-app-silverlightwinrt/

 


 

For SQLite Studio you can refer to the following link

http://sourceforge.net/projects/sqlitemanstudio/

 


 

Step 2:
Now using isostorespy tool you can easily export it on your pc from local storage.

 


 

Pressing the following button as highlighted in the figure you can download the sqlite database from the windows phone local storage.

 

Step 3:
Open the downloaded database file using SQLite studio.

 


 

You can browse the contents of your database easily.

 


 

I hope this post will be helpful to you.


SQLite Database in Windows phone app – Part 2 (SQLite Operations)

In my last blog post I have explained you how to install and setup SQLite Database in your Windows Phone app Project. In this post I will explain you how to create or delete a database and how to perform different operations like insertion, deletion & searching etc.

We will be working on the same project that we have created in last post. So if you have missed that post you can view it from the link given below. And follow the steps given below.

SQLite Database in Windows phone app – Part 1 (Installation and Setup)

 

Step 1: Create a new folder called Database in your project and add a class to it having the name Schema.cs.

 


 

Step 2: Now create a table called Students in form of class that we need to include in our Records.sqlite database.
The class having the name Students with all the getter and setter methods have been given below.

 


 

 

Note: One property needs to act as primary key and its value should be unique for each record. In this example Id of student acts as primary key.

Step 3: So it’s time to perform all SQLite operations. So I thought to make a single helperclass called ‘DatabaseHelper.cs’ in Database folder and handle all the SQLite operations with this helperclass.

 

 

Step 4: This is the main step where we will be writing all the SQLite operations in the helperclass.

 

 

1. Creating a Database While creating a database we need to first check whether it exists or not. If not then create a new database. The code for the following is given below.

 

 

Note: You can create more than one table in a database. In this post we have just created one table to keep things simple.

2. Deleting a Database
Note that database is created as a storage file in Windows Phone app so to delete it you only need to delete the following storage file. The code for the following is given below.

 

 
 3. Adding a new record The best practice while adding a new record in the database is to first check whether database with following name exists previously or not and then insert a new record. The code for the following is given below.  

 


 
4. Updating an existing record
To update a record in database we first need to query that object from the database and then only we can make changes to it. The code for the following is given below.

 

 

Note: In this example we are updating the marks of the student with given id using the search query.

5. Deleting an existing record Similar to updating an existing record you first need to query the record from the database and then perform the deletion operation. The code for the following is given below.

 


 
6. Selecting all students from the database
The code for fetching all the records from student table is given below.

 

 
Note: The full code for the DatabaseHelper.cs is given in this link.

Step 5: Now after writing the code for database operations the next step is to create the UI for the above and bind the data to it. On MainPage.xaml create 4 different buttons as shown in the figure below.

 

 

The code for the Design view is as following  
 

 
Different buttons are

1. Create Button– This button is used to create a new database. The code for the click event handler is as given below

 
 
 

2. Delete Button– This button is used to delete the current database if exists. The code for click event handler is given below.

 
 
 
3. Add a new record Button– This button navigates to new page. Where we can add a new record into the students table. The code for click event handler is given below.

 

 

4. Display all records Button– This button navigates to a new page. Where we can view all the records and delete them from the table. The code for click event handler is given below.  

 

 

Step 6: Create two new pages having the name AddRecord.xaml and Display.Xaml in your project.

 


 

AddRecord Page

In this page we insert a new record into the table

 


 

The code for xaml page is given below

 

 

When use clicks on the insert button the record is inserted into the database. The code for the click event handler is given below.

 

 

Display Page

In this page we display all the records that are present in the database as shown in the figure below.

 

 

The code for the xaml is

 

 

And the code for the Display.xaml.cs is as following

 

 

Note: In both of the pages we have made use of the functions defined in DatabaseHelper.cs.

 

Step 7: Add the following code for back button press in App.xaml.cs to control the navigation from one page to another.

 


 


 
If you have any doubts related to this post you can download the full source code of the project from the link given below.

SQLiteDatabase.zip

In my next blog post I shall explain you how to explore SQLite Database using IsoStoreExplorer tool.

http://windowsapptutorials.com/windows-phone-8-1/sqlite-database-in-windows-phone-app-part-3-sqlite-exploration/

SQLite Database in Windows phone app – Part 1 (Installation and Setup)

While developing applications there may be a need to store data and access it for later use. Windows Phone provides us with different ways to store our application data depending on the size. But when dealing with large data involving multiple entries, database is the appropriate method.

 

Windows phone 8.1 Runtime app supports SQLite database. So in this article I will explain you how to install and setup SQLite database reference in your windows phone application.

Follow the steps given below

 

Step 1:
Create a new Project having the name SQLiteDatabase.

 


 

Step 2:
Install the SQLite for Windows phone 8.1 SDK

Go to Tools->Extensions and Updates

 


 

Then type the keyword sqlite in search bar in the online tab. And install the SDK SQLite for Windows Phone 8.1

 


 

Note: If you don’t find the required library in Visual Studio gallery you can download it from the required web page.

 

Step 3:
Add the SQLite Reference to your Project

 


 

Go to References->Windows Phone 8.1->Extensions

 


 

When done, you will see that the proper references to SQLite and Visual C++ 2013 Runtime have been added to your project

 


 

Step 4:
Change the target Platform of your Project

You may have already noticed, that the references show a warning symbols, to resolve that the next thing to do, before compiling the solution is changing the architecture of the target platform. This is the fact that the engine of Sqlite is written in C ++, and the default target platform set in the project is Any CPU. This mode is not supported.

So in order to resolve this go to Configuration Manager as shown in the figure below

 


 

In the next dialog, we note that we have several choices of platforms, Any CPU (the default), ARM, x64 and x86.

Now we change the target platform accordingly. If you want to debug your app on Phone then choose the ARM Platform. But if you wish to debug your app on Emulator or Windows PC select x86 or x64 configuration depending on your processor if it is 32 bits or 64 bits.

 


 

Note: Every time you change your debugging option from emulator to phone you need to change the debug configuration accordingly.

 

Step 5:
Installing sqlite-net package

After installing the library for SQLite, we need sqlite-net NuGet package. With this library, we will be able to perform all the operations that you normally do in a database, such as Insert, Delete, Update and run search queries. This package provides two helper classes (SQLite.cs and SQLiteAsync.cs).

To install it right click on the project->Manage NuGet Packages and search for sqlite-net

 


 

Finally we have completed the SQLite setup. In the next blog post I will be explaining you how to perform different operations like insertion, deletion and searching in SQLite database.

 

http://windowsapptutorials.com/windows-phone/sqlite-database-in-windows-phone-app-part-2-sqlite-operations

How to access Isolated or Local Storage Data of Windows phone App (Silverlight/WinRT)

Initially you guys have been using Isolated Storage Explorer (ISETool.exe) to access the Isolated/Local Storage data of your Windows phone applications. But that requires typing long commands into the command prompt with app id. You need to remember different commands in order to access different files and is a hectic procedure.

But now we have got a new tool which can make this access easier and provides a GUI interface with upload and download features.

The tool is called IsoStoreSpy. It is an open source project hosted under the Codeplex community.

The download link for the tool is given below. You can download the version that suits your environment.

 

Download IsoStoreSpty tool

 

Step 1:

Now to start with first you need to open the tool

 


 

Step 2:

Click on the Settings icon in the middle or the top-left side of the tool. Now you need to select the device.

 


 

Step 3:

If you are running on the device then select Device or else Emulator. If you are running on an emulator then please install the app in the emulator and be sure the App is Not Running. So that this tool can access your app’s settings file or correspondingly in the phone just install the app and be sure the app is not running.

In this case we are assuming the app is running on the emulator.

 


 

Step 4:

Now by default it will show all the files in the local folder of the application. To view the files under roaming settings select Roaming under the Directory section.

You can also import or export a file into the application through this tool.

 


 

I hope this post will be helpful to you.

How to use Converters in Windows phone app (Silverlight/WinRT)

ValueConverters can be used whenever we need to present data in an easy and controllable way such that it doesn’t interfere with other layers of the application.

Converters are called by the Data Binding mechanism whenever binding actually occurs (for example, when a control is notified about the change in the underlying property).

 

ValueConverters need to implement IValueConverter, a simple two-method interface. The two methods are

1) Convert – Modifies the source data before passing it to the target for display in the UI.

2) ConvertBack – Modifies the target data before passing it to the source object. This method is called only in TwoWay bindings.

For more reference you can see this link.

In this following blog post I shall be demonstrating you how to create an indexvalue
converter for your Windows phone app. The different steps you need to follow are

 

Step 1:

First create a class having the name IndexToColorConverter in your Project.

 

 

And add the following code to it as shown below.

 


 

Silverlight

WinRT  
Note: The only difference between Silverlight and WinRT is that the data type of parameter culture has been changed to string in WinRT.

 

Step 2:

Open the XAML page where you need to use this converter and add the following code in the namespace of the XAML page.


Note: Here Tips8 is the name of the Project. You need to replace it with your own project name.

 

Step 3:

Add the following code into PhoneApplicationPage page resources section in the XAML. It will create a Static resource within the XAML page with a specific key which will be used by the UI elements further.

 



  Note: The name of the key can be same as the Class name of color converter or something else. In order to avoid confusion we have kept both names as same.   Step 4: Now in the UI element just bind the property you wish to do so. For example in our project we have binded the Background Property and have assigned the IndexToColorConverter to it. The code for the following is

Note: Here index is the object property to which button is binded.

 

If you have any doubts regarding data binding you can refer to the following blog post.

http://windowsapptutorials.com/windows-phone/data-binding/data-binding-in-windows-phone-app-one-way-binding/


Reading and Writing in an Existing text file in Windows phone app (Silverlight / WinRT)

This is a small blog post in which I shall be explaining you how to read and write to an existing text file which is present locally in your project.

Let us suppose the text file is having the name myfile.text and is present under main root directory.

 


 

Step 1:

Now first thing you need to do is to set Build Action to Content. And, change Copy to Output Directory to Copy Always. This will ensure the file itself ships with your application. If it doesn’t, you won’t have a file to read.

 


 

Step 2:

Now you can read and write your text files easily as shown in the code below

 

Windows Phone Silverlight

Reading

 

 

Writing

 

 

WinRT

In WinRT you can access files in the local app data store using the “ms-appdata:///local/” protocol. To access files in the app package, use Windows. ApplicationModel. Package. Current. InstalledLocation.

Reading

 

 

Writing

 

 

Note: Suppose your file is not located in main directory and is located under the root folder Files as shown below.

 


 

Then file name would be


Note: You can use the same technique for an xml or json file.