Category Archives: Windows Phone 7

Update to my Trial Mode post

So I just release an app to the marketplace recently. (Check it out here http://underbridgecity.net/underbridgegraffiti/) And I implemented the trial code I mentioned in my Trial Mode post (http://www.underbridgecity.net/blog/2012/03/trial-mode-in-windows-phone-7/) so that when you bought the app and then pressed the back button you should be in full mode and not trial.
I tested it out, and it worked! I went into the app, clicked a button to go to the marketplace to buy it, bought it, went back… and I had to press back an extra time but then went back into the settings page and the app no longer was in trial mode.

So if you implement trial mode, I suggest adding in the check if trial or not in the application activated section to always check when you navigate to the app no matter how you get there.

I will upload a video soon of me buying it.

Multitouch in WP7

I just published an app. (You can check it out here http://underbridgecity.net/underbridgegraffiti/.) Has the ability to allow more then one finger to interact with the screen at one time. Here is how I was able to set it up on a canvas which is set up in the xaml.

So to get multitouch set up I used a TouchFrameEventhandler. You will have to add

as a reference and a using statment.

I created a class called DrawingPoints and then created a list collection of them.

Read more »

My app Under Bridge Graffit was published

Just a small update. My app Under Bridge graffiti was just published in the marketplace. You can check out the page I made for it here http://underbridgecity.net/underbridgegraffiti/

I will soon blog about how I was able to get multi touch set up in the app. Also I am going to test out how I set up trial mode to make sure that if a user hits the back button after buying the app, it checks on activate so you don’t have to restart the app.

Different Templates in one Listbox

In this post I will explain how I selected different templates based on the type of data I wanted to show in the same listbox.

Now why might you want 2 different templates in the same list box? Well what if you wanted to display different tasks and appointments for a single day. But you want to see at a quick glance what a task is and what an appointment is. So lets say you have a square for all tasks and a circle for all appointments.

To do this you will use a ContentControl which as the data gets bound to the listbox, we will override the method to check if the item getting bound is a task or appointment. And then set the template depending on what it is.

In my code example the tasks and appointments both inherit from a class called CalendarItem. This is an object orientated programing principle, and if you don’t understand it let me know and I will create a blog about the basics of it.

Read more »

Overwrite WP7 Style Theme

I was working on a Windows Phone 7 application and the client wanted to always have the light theme and have a special accent color depending on settings inside the app. They wanted to do this for branding reasons so I had to find a way to always have this app look like it was in the light theme and override the accent color to the colors they wanted.

I will now go over how I did that. You can use this to always have the light theme for the app like the native mail app, or even create your own custom theme.

In the code I created a method in the App.xaml.cs file, and this method get called in the constructor for App() before the InitializePhoneApplication() call.

You will also need to set teh background on all the pages to {StaticResource PhoneBackgroundBrush} like

I tried to document the code so you can understand what is going on line by line so I will give a little explanation here.

The line

loads the theme you are going override. Here I copied a default theme resource file (Edit: the theme resource file is ThemeResource.xaml) from the design folder located on my machine at C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Design\LightBlue and called it LightTheme.xaml. If you look in the design folder you will see many folders.

Then the code went though all the entries and compared the ResourceDictionaries, if the custom theme file contains the key name of a main style element, it will overwrite it’s brushcolor. If you look at a default theme resource file, it contains a bunch of colors with keys and the keys are pretty self explanatory. So if you wanted to create your own custom theme you can start by copying and editing one of those files.

Also in my code you see me checking a setting value and then overriding the accent color depending and the user setting. This isn’t required unless you want the user to select a special accent colors in the settings or want them to change, if you just want one over ridden accent color just put it into your style resource file.

And questions or comments just let me know and thank you for reading.

Trial Mode in Windows Phone 7

While building my apps for WP7 that users will pay for, I like to create a trial so the users can try out my app before they buy it. But when you are debugging your app there is no Trial simulation. So Looking on the web I found one.

Here is what i do to simulate trial mode in my Windows Phone 7 apps.

First at the top of your App.xaml.cs file add this

*EDIT*
I forgot to put this in here at the top. You need it to access the licence information.

and to use that you will need to add in the folling using statment.

*END EDIT*

I usually add that in right under my RootFrame property.

I then create a method in my App.xaml.cs

I then put the CheckLicence method into my Application_Launching and Application_Activated methods in my App.xaml.cs file to check if the application is bought or a trial version.

Then in your code you set up what will happen in your trial version and all you have to is check the IsTrial if true, it is a trail version. If false it is a full/paid version.

I hope this helps you out creating your WP7 app!

(EDIT: Putting this code in will check if trial or not after you buy the app, check out my post here http://www.underbridgecity.net/blog/2012/04/update-to-my-trial-mode-post/)

What is this ViewModel?

Now I will explain a little bit about MVVM. MVVM is an architectural pattern. It stands for Model View ViewModel. Wikipedia has a decent explanation about it (http://en.wikipedia.org/wiki/Model_View_ViewModel)

The way I view MVVM is like this. It separates the Data(Model), from the presentation(View) and the ViewModel handles updating the Data when something changes on the View. It is useful, but I also feel if you are doing simple little apps you don’t need to use MVVM as it just takes up to much time and resources. But it is also a good thing to know and understand.

If you created have checked out my previous posts and followed along, you should have noticed folders in the project that separated the Model, View and ViewModel out. If you wanted you could also check out the MVVM example from here (http://msdn.microsoft.com/en-us/library/ff431744(v=VS.92).aspx#BKMK_Common) also check out this short video if you want. http://msdn.microsoft.com/en-us/Video/gg241309

So if you start to notice in those examples, The view uses the ViewModel to get and set data to display and change, and the ViewModel updates the Model when it is saved. They do this as seperation of data and presentation. Separation helps with cleaner looking code and also has the ability to have a designer working on the View while a developer works on the data and that. But like I mentioned before if you are building a simple app, doing it in MVVM can cause a lot of overhead that isn’t really needed, but I still encourage you to try building an app with the MVVM pattern to get use to it.

I am still learning MVVM and have only had so much experience with it, but if you plan on really getting into WP7 application development, I suggest you read up on MVVM and try to build an app using the MVVM pattern. Any suggestions for me about MVVM or any questions please let me know.

Lets go into the solution!

Now that you have created your sample pivot application from the previous blog post. (http://www.underbridgecity.net/blog/2012/02/a-new-project/) We will talk a little about what is going on. To the right inside Visual Studio you should see the solution explorer.

I will explain what the files in the solution explore are and what they are used for.

A solution is a… solution! A solution is a a collection of projects that are used to create the whole program. We only have one project in our solution and that is all we really need right now.

A Project holds a set of files and in our case this project is the silverlight for windows phone project. The project file is named “SamplePivotApp” in the image above. If we wanted we could create another project and have our windows phone project reference it, but I will get into that into a future post.

Now onto the folders in our project, you will see a Properties folder which contains files that is used for meta data for our app. If you wanted open them up and look though them, but don’t change anything in them right now. For our Windows Phone 7 app the most important file is the WMAppManifest.xml. This file contains information on what our app can do, if it belongs to a special app hub on the phone (like the games hub, pictures hub or music hub.) If you are not familiar with the term hub in windows phone it is what Microsoft referes to as its sections on the phone. If you have access to a windows phone, you should see the different tiles and if you open one of the hubs I mentioned above you might see some apps in there. That is becasue those apps relate to that hub, so if you create a game you will want to put it in this game hub, and you can do that by changing the Genre attribute on the app tag to “apps.games”.

Read more »

A New Project…

Ok now it is time to get started. Open up Visual Studio. I am using Visual Studio 2010 Professional version, if you have Visual Studio for Windows Phone Express that is perfect for building windows phone 7 apps. I will now refer to Visual Studio as VS.

Once you open up VS you should see a welcome screen and in the upper left see a link for a New Project… Click that.

Then you should see a screen where you can select what type of project you would like to make. Here I selected a Windows Phone Pivot Application. Give it a name and click ok. The name is the name of your project, this will create a folder in your projects folder for VS. This doesn’t have to be the name of your app.

Read more »

Time for a plan.

Well my WP7 game was just published to the marketplace. If you want to check it out, the name of it is LeftOrRight. Or you can click here to check out a site I made with this awesome Wp7 app template page. http://www.underbridgecity.net/leftorright/ If you like the page template, and want it for your own WP7 app you can get it here WP7 App Site and it is by Nick Harewood

Ok now to get started on creating your own app. First this first, you need to come up with an idea. It doens’t have to be this grand idea that will solve all the world issues, start small and simple. I thought of my idea as I was waiting to play a hockey game. It started with me thinking, “I want to create an app that I can get into the marketplace by the end of the week.” I didn’t get it in by the end of that week, but I wanted something I wouldn’t spend a long time on. So I came up with a simple game of guessing left or right. Sounds simple right, and it kinda was.

Before I even hit File > New Project, the first thing I did was pull out some paper and write down my thoughts. I wrote down my objective, “A game of guessing Left or Right that uses the WP7 Metro interface.” Next I started planning out how I would do that. I decided to keep it all in a silverlight project and not XNA to make it easier and also there would be no graphics in it.

Then came the parts where I wrote down my plan on how I was going to code it. It went like this,

1. Design the UI.

1a. Create Pivot page with 3 pivots. b. add buttons on each page. c. have a score always display and not change with the pivote pages.

2. Start the coding

2a. hook up button events. 2b. Create the functions to get the anwser and check the anwser. 2c. Hook up UI events to code funstions

3. Test it!

3a. Test

 

That Was my original plan, and Lets just say there was a lot more added in after I started work on it and there was more after test it… like recode this, make this look nicer, test it again. But At least I had a starting point. So if you want to start your own app, I suggest taking just a few min to plan out what you are going to do. I don’t think you need a fully designed idea before you start programming a starter app, it could help but I like the approch of having a general idea at first and then diving right now.

So get cracking, think of an idea, make a plan. If you need help or just want to play araound with some sample projects check out. http://msdn.microsoft.com/en-us/library/ff431744.aspx

Happy Coding!