The world's coolest Laptop

Computing technology

The perfect UI for a logon screen

Communications has made our world tiny

Cant live without one

Monday, January 9, 2012

Buttons in Listbox–WP7

Its really wonderful and dynamic to have a button associated with every element of listbox. This is really advantageous if you running short of screen space (often the case in phone applications).

This is an extension of data binding techniques.But how do we know which element’s button is tapped because while defining the button using binding we give a single event handler. One more constraint not in many cases we will not know the number of items in the listbox. So lets see what can be done about this.
1[6]

Prerequisites:
  • You should be aware of the data binding techniques in WP7. If not please read my blog post on data binding to listbox in wp7
  • You should have basic understanding of wp7 app development
  • You should have the Windows phone 7 SDK installed
Here I am going to start from the point where I assume you have done data binding as I said in my data binding blog post. If not I would recommend you to download the source code from my previous blog and start off with that or if you are a Pro start of with from scratch.
Now in the listbox.itemtemplate tag I where we have add elements to define the structure of an item, add a button at the last in the textgrid. The code is
<Button Name="hello" Margin="0,100,0,0" Height="70" Content="Tap" />
Now select the button and goto the properties, select the events tab, and double click on the field besides the click ( Basically create an event handler for the click ). You will be redirected to the C# page. Come back to the XAML page. You should see the code of the button modified as follows..
<Button Name="hello" Margin="0,100,0,0" Height="70" Content="Tap" Click="hello_Click" />
Now the entire code of the item template will look something like this.
<ListBox Height="373" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Top" Width="439" Margin="0,41,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="-200,0,0,0" Name="masterpanel">
<StackPanel Width="100" Height="100" Margin="0,0,0,0" Name="imagepanel">
<Image Source="pic.png" Stretch="Fill" />
</StackPanel>
<Grid Margin="300,-100,0,0" Name="textgrid">
<TextBlock Text="{Binding name}" FontSize="25" Foreground="Gold"/>
<TextBlock Text="{Binding phone}" Margin="0,50,0,0" FontSize="25" Foreground="Gold"/>
<Button Name="hello" Margin="0,100,0,0" Height="70" Content="Tap" Click="hello_Click" />
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>



Alright. But still I have not told you the solutions for the constraints Lets get to that now. There is a property called the TAG associated with many elements and its also present for button. Now we are going to use this to know from which element the button was tapped.
Untitled[7]

As we can see first lets bind some data to the tag property. The data should be such that it should be unique to every element. Here I am going to bind the name. When I tap the button I will get a message displaying the name.
So first lets add Tag="{Binding name}" to the XAML code of the button. So the button code should be looking like this.
<Button Name="hello" Margin="0,100,0,0" Height="70" Content="Tap" Click="hello_Click" Tag="{Binding name}"/>

Now in the event handler where you add the items to the listbox and bind them ( in the previous blog post example it should be the event handler for the add button), the moment you add the tag gets associated with the button of that item.Here since I am using name that is already used in textblock the code is same. However if you would like to add something else make sure you add the property and make necessary modifications in the XAML code.

Now the next step is to retrieve the tag. Now this syntax is the key thing of the entire process. In the event handler hello_Click use the following code to retrieve the tag.
string name = (string)((Button)sender).Tag;
Basically we are typecasting the object sender into a button since its called from a button click and accessing the tag property and type cast the output to a string and then store it in the variable name.

Now we have retrieved the tag. Next step is to process and get the required output. Here my aim is restricted to just displaying the name of the item I call
So I am going to write the following code
MessageBox.Show("The name of the item you tapped is " + name);
So the event handler function hello_Click should have this code:
string name = (string)((Button)sender).Tag;
MessageBox.Show("The name of the item you tapped is " + name);


So that’s it. Launch the application tap on the button in every item and notice the output.
3[3]

You can download the source code from here.

Sunday, January 8, 2012

Ultimate alarm pro



Ultimate alarm pro an Alarm and reminder application application built for WP7.5 .I am going to describe something about this application.

Ultimate alarm pro has some incredible features that no other alarm application has for wp7. It is built using silverlight and C#. Some of the features of this application are as follows:
Pop up alarms : When you set an alarm a Pop up comes up playing the alarm tone. Now if you tap the pop up it will take you to Today’s portfolio which has every feature that you require after an alarm.

Unlike many alarm applications that require you to keep the application open and keep the phone plugged in as it drains the battery this application does not require this. You can set the alarm and and close the application. So basically your BATTERY IS NOT DRAINED.



Sleep Timer

My favorite of all the features. Many of us want to listen to some music before going to sleep. Sometimes I jus sleep with music on and the next day morning I find there is nothing left in the battery. Very annoying. So here is sleep timer. Listen to the songs in your phone set a time and start the timer the application will automatically stop playing the music and exit. So again No BATTERY DRAIN

Wake up test:

Even if the alarm is there we just press something and go to sleep again. So here is wake up test. If you enable this feature from settings then the app will keep playing the alarm tone till you pass the wake up test. The test is that you have to enter a number that is displayed on the screen randomly in a small size. So its mandatory you wake up and enter the number.


Today’s Portfolio

Today’s portfolio is the page which displays everything you need after an alarm occurs:
  1. Weather and time : App reads the time and weather as soon as you come as soon as you tap the pop up (If you have enabled it). Weather is got using yahoo weather api.
  2. Calendar entries : It displays the calendar entries of that day since you may want to have a look at what’s lined up for that day
  3. News : Read the headlines offered by Bing  Top 10 headlines are displayed her.
  4. Alarm associated reminders : Sometimes we need to do something important the next and definitely we don’t want to forget that. So while setting the alarm tap on the associate a reminder and that will be displayed as a message here. So with this you are permitted to forget it as the app will remind you
That’s not all there is a lot more.

Favorite alarms

You can set a favorite alarm within 2 taps after you enter the app. A favorite alarm is remembered by the app always. You can use favorite alarms for the alarm like the ones you use regularly ( time of getting up in the morning etc). Maximum of 3 favorite alarms can be set.

 


You can also make the application read the weather and time in FIVE LANGUAGES
  1. English
  2. French
  3. German
  4. Spanish
  5. Italian
A lot more small features are also there like timed alarm etc. Check it up in the marketplace do rate the application.
market

Med Prompter Pro


Med prompter is a medicine reminder application. It’s a simple utility presented with an incredible user interface,

Some of the features of this application are as follows

Reminder for each dose of each medicine:

















You can setup reminders for every dosage of each medicine. The reminders are set for the time you wish to take your medicines. If you tap the reminder pop up( as in the pic on the left) the medicines that are to taken that time are displayed as a list (picture on the right)

Flexibility with the medicine dosage:




Medicine entry is made very flexible with the timings and the days is left to the user. This is very flexible compared to some similar applications where this flexibility is not given and the user is forced to get reminded about applications when he doesn’t require; for example some applications force the user with options like alternate days, once a week and stuff. Where as in this application user can choose any day he wants and any pattern.





Type of medicine:

The type of medicine is displayed in the list through a picture like the one shown in the first picture. Five types of medicines are supported:
  1. Pill
  2. Cream
  3. Liquid
  4. Drops
  5. Inhalational





Details of your medicine is stored:

Forgot to take the prescription to the drug store? Don’t worry you can retrieve the major details from this application. The details like the name, amount , type , total amount of medicine is permanently stored unless you chose to delete that.






Refill Prompter:

A refill alert is shown when your medicine starts to run out with a small symbol, This is calculated based on the input given by you ie., the amount taken per dose and the total dose available with you. If it starts to become less than 10% then a refill alert is shown in the app’s main page and the page when that particular medicine is reminded.





Lot more small features like when is the next dose,call doctor, help in every page etc. is there in the app . Check it out and do rate it.

market

Insurance emergency assistance

 

Insurance emergency assistance is an app that is used to manage insurance policies and to get the services specific for insurance during emergency.This application is built using Silverlight and C#.

 

During emergency , say if a car accident occurs we normally tend to forget the number of the insurance fellow, policy details etc. Next, you have to run behind him submit proof etc and then claim the damage cost.

Now with this application all the services that are required when an emergency occurs is present. You can store the phone number or mobile number or email of the insurance company or agent. During emergency all you need to do is select the policy that you stored previously and call or message or email.

The SMS and EMAIL functionality will automatically pop up the a default sms with the policy details as well as your location. This also helps you to produce additional proof for the accident or what ever emergency situation.

Now that’s not all. There is more to this application. It also helps you manage insurance policy ie., an insurance manager.

You don’t need to run behind papers everytime for your policy details. You can store the details of all your policies in this application retrieve it whenever you want. Also it has an inbuilt function to remind you of the due date of all the policies and display an alert if the policy crossed the due date.

market

A lot more small features included in the application. Check it out in the market place .Do rate the application.

Finance Manager beta


Finance manager beta is an application i have designed for windows phone 7. I have given a brief summary of the app here. Check it out.






Finance Manger beta is an app that helps in financial management needs on the go. Combined with an user friendly interface the functionality of the app includes calculations related to loans, expense tracking and much more. 
 Some of the main features  are discussed here:

1.       Financial Calculations :

a.       Loan Calculator: Loan calculator is a feature which gives user everything he needs to need to know about loan. It can calculate

                                                               i.      EMI

                                                             ii.      Principal for every installment

                                                            iii.      Balance after every installment

                                                           iv.      Interest for every installment

b.       Loan comparator: Loan comparator helps the user to compare two loans. It can simultaneously present the user with the EMI, Annual difference, Monthly difference for both the loans enabling the user to identify which is suitable to his/her needs.

 
c.       Forex Calculator: Forex calculator converts the money equivalent of one currency to other. It has support for about 38 major currencies in the world. The results of the calculator are approximate values to aid the user in approximate foreign exchange calculations even if the user is devoid of access to internet.
1.    Expenses :
Finance manager beta gives an entirely new dimension to expense tracking. With this the user can instantly update his expenses, thus the traditional problem of forgetting the expenses is no more.  
                                


                 


As quoted earlier user friendliness is the main aim of this app. The page provides exclusive access for the user to input that particular day’s expense directly through quick feed today’s expense and view them using view todays expenses so that the hassle in selecting the date and then navigation.
 
a)    Expenses management: Expense management is very much easier with finance manager beta. It presents the user with the expenses in a variety of ways. The user has also the option of adding new expenses, editing previous expenses even for the previous days. Above all It categorizes the expenses.
b)    Report: Finance manager beta also generates report for every month. It presents the user with a bar graph with different categorical expenses and the total expenses. The user can also view categorical expenses separately for that month (by clicking bar Corresponding to that category) so that he can identify the area where maximum expense occurs

 
c)    Search : If the user forgets which date the expense was made, the details can always be retrieved using the description that was provided earlier while feeding the expense.


                  
d)    Cash in Hand feature: The cash in Hand refers to the amount of liquid cash one has. It is updated in real time as the expense is made or if withdrawal or deposit is done. It helps the user to match the cash in hand in the app and his actual value. This enables the user to know the present status, find if some expense has been missing from record etc.




.


3.Bank accounts :
         Bank accounts is a small feature that helps the user in tracking the balance of all the bank account one has. This removes the hassle of referring several documents and asking the bank representatives and other means for getting the balance particularly if one has multiple bank accounts. 
 

Additional Features:
1.   Password Protection: Password protection is given for this app. This makes sure that nobody other than the user of this app has access to the financial data. The user has also got options to change or disable the password option and re enable as one wishes to.
2.  Customized Help: User friendliness is one of the important parameters that was considered while developing the app. But still if the user has some difficulty there is always help given in almost all the pages giving descriptions and information about the functionality of that feature. This enables the user to understand the feature of the app then and there.


Comments and suggestions are welcome. Please note that the app is in beta stage and there are chances of bugs being there.

The legal details document can be downloaded from my skydrive. Click on the following folder to access my public skydrive and click legal details to download them

Item template & Data binding with listbox–WP7

ADDING PICTURES AND FORMATTING THE DATA IN LISTBOX

The listbox is an element that is used to display a list of data. The default manner in which the data is presented in the listbox sucks. So we are going to format this by using a technique called data binding. I am going to show how to add pictures and do some formatting with the data.

Advantages:

  • Enables you to present multiple data in a single element. For example a single element can display the name, address phone number and a picture
  • The design seems really better with data binding when compared to a list of words
As we can see the default listbox(left pic) is really not that good. We are going to transform that to the style shown in the second picture(right pic)

Lets try to format the listbox now.

 

Prerequisites:

  • You should have a basic understanding of wp7 app development
  • You should have the Windows phone 7 SDK installed

The first step is to encapsulate your data or the properties that you want into a single element - class. For the sake of demonstration I am going to add a picture a name and phone number  (i.e., those things that you want to display in a single item of listbox). This class I am going to write it in the Csharp page that is the .cs file associated with every XAML page.

public class list
        {
            public string name {get; set;}
            public string phone {get; set;}
        }

Now go to the designer page ie., the XAML page and drag and drop a listbox into the UI. This will automatically generate the XAML code for listbox. Now we need to change the template of every item of the listbox. So we are going to do some modifications to the XAML code of the listbox.

<ListBox Height="373" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Top" Width="439" Margin="0,41,0,0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="-200,0,0,0" Name="masterpanel">
                            <StackPanel Width="100" Height="100" Margin="0,0,0,0" Name="imagepanel">
                            <Image Source="pic.png" Stretch="Fill" />
                            </StackPanel>
                            <Grid Margin="300,-100,0,0" Name="textgrid">
                            <TextBlock Text="{Binding name}" FontSize="25" Foreground="Gold"/>
                                <TextBlock Text="{Binding phone}" Margin="0,50,0,0" FontSize="25" Foreground="Gold"/>
                            </Grid>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

How it works?

The first xaml tag that is inserted is the <ListBox.ItemTemplate> which is used to define the item template of that listbox. The second tag <DataTemplate>is where we define how the data is structured in the item template . Then we create a stackpanel called master panel that holds all the items we need in the item. Here our listbox needs a picture, 2 textblocks one for name and the other for phone number. Now we create another stackpanel called image panel for holding the image and give the image source and other details like the source in the tag.Next we create a grid to hold the 2 textblocks

Now notice that the property text of both the textblocks are set as

Text="{Binding name}"  & Text="{Binding phone}"

This is Data binding meaning dynamically get the data and use it here. Notice that the property of binding is set as Binding name and Binding phone where name and phone are the exact property names of the class we declared earlier. If they are not exact the data wont bind properly.

Here for the image I have not used data binding . But if you want different images for different elements you can use the same technique of data binding to the source property of the image.

Key thing:

The key thing thing is that I have altered the margins of every element so that every element gets arranged the way I want it. So you need to this based on trial and error basis which is slightly annoying but never the less worth the pain. This process is going to drive you crazy but do have patience.

Another key thing is that you need to make sure that all properties in the class are public and the class is public. Else even if you add data to your listbox it will appear blank.

This process can also be done using Expression blend which has a easy to use graphical interface and a lot more.

Continuing …. :

Now I add a button and handle the click event so that it adds items to the listbox. I created a new object of the class called obj1. Now I set the properties name and phone no with some sample data (here I use listbox’s count + 1 just for the sake of demonstration). And then add that object to the listbox item list.

private void button1_Click(object sender, RoutedEventArgs e)
        {
            list obj1 = new list();
            obj1.name = "Name " + (listBox1.Items.Count + 1);
            obj1.phone = "Phone - 100" + (listBox1.Items.Count + 1);
            listBox1.Items.Add(obj1);

        }

 

And that’s all its over. Launch the application!!

You can download the source code from here. .

If you have any queries please leave a comment.