Short Courses: Game Development using Unity3D

Unity 3D

Unity 3D

Game Development has found a new base in Mobile, Tablets and Desktop in recent years. Learn Unity 3D using C# language to learn the basics of developing Games that can be targeted for any platform. This course is totally practical and provides hands-on experience to the participants. Students are expected to bring their own Laptops/Notebooks.

The fee for this course is PKR 2,800 and all the fee collected will be donated to Mishkat Welfare Trust
From: 21st June to 6th July 2014 (Weekends only)
Timings: 9:00 AM to 12:00 PM
Venue: Olives School, Judicial Colony, Rawalpindi.

Limited transport facility available for female students. Please mention it in the Comments field and provide your address.

Programmically Adding Items to ListView Control in WPF

A ListView control is similar to a ListBox but can contain multiple columns. But to add data we need to bind it to an object which has the same data members as the columns of the ListView control.

This is how I have declared the ListView and its columns

<ListView Name="list">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Serial No." DisplayMemberBinding="{Binding Serial}" />
            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
            <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Age}" />
        </GridView>
    </ListView.View>
</ListView>

Notice the Binding values. Now I will create a class named Item (you can name it anything you like)

class Item
{
    int serial;
    string name;
    int age;

    public Item(int s, string n, int a)
    {
        serial = s;
        name = n;
        age = a;
    }

    public int Serial
    {
        set { serial = value; }
        get { return serial; }
    }

    public string Name
    {
        set { name = value; }
        get { return name; }
    }

    public int Age
    {
        set { age = value; }
        get { return age; }
    }
}

The property names of this class matches the binding values. Finally we can add new items:

list.Items.Add( new Item(1, "Ibrahim", 21) );
list.Items.Add( new Item(2, "Sumayyah", 15) );
list.Items.Add( new Item(3, "Yusuf", 20) );

This should work

How to use Delay in WPF

The problem at hand is that we want to simulate a Progress Bar as if there is some processing going on. If you simply apply a loop to change the value of the progress bar, the loop will end without the user even noticing any change. For the delay we need to use the DispatcherTimer that is available in the System.Windows.Threading namespace.

using System.Windows.Threading;

First have a look at the XAML code:

<Grid>
    <ProgressBar Minimum="0" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Maximum="100" Name="progressBar1" VerticalAlignment="Top" Width="479" />
    <Button Click="button1_Click" Content="Button" Height="23" HorizontalAlignment="Left" Margin="230,105,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
</Grid>

We simply have added a ProgressBar named progressBar1, Minimum as 0 and Maximum as 100. Also we have a Button with a click event named button1_Click.

Now what we need is that when the user clicks on the button, the progress bar starts simulating. So that code will be placed in the button1_Click method.

private void button1_Click(object sender, RoutedEventArgs e)
{
    DispatcherTimer delay;
    delay = new DispatcherTimer(DispatcherPriority.Normal);
    delay.Interval = TimeSpan.FromMilliseconds(30);
    delay.Tick += new EventHandler(delay_Tick);
    delay.Start();
}

We have created an object of the DispatcherTimer named delay and set its Interval to 30 milliseconds. Next we have created handler for the Tick event (this event will be called every 30 milliseconds in our case). Finally we have started the delay timer.

In the Tick event handler we need the following code:

private void delay_Tick(object sender, EventArgs e)
{
    progressBar1.Value += 5;
    if (progressBar1.Value >= 100)
       ((System.Windows.Threading.DispatcherTimer)sender).Stop();
}

For every Tick event, the progressBar1 will progress with a value of 5. To stop this timer after the progressBar1 has reached its destination we need to stop the timer.

Hopefully this was easy. Post your questions if you have any.