Displaying image inside Panorama Title in Windows Phone applications

Although it might seem too obvious, but still many developers and designers forget that top-margin should be equal to 80 for the content inside Panorama Title(in my example bellow Margin=”0,80,0,0″ for Grid element). Bellow is the XAML markup that you might use to display an image inside Panorama Title in Windows Phone applications.

<controls:Panorama>
    <controls:Panorama.Title>
        <Grid Margin="0,80,0,0">
            <Image Source="{StaticResource ApplicationLogo}"
                    HorizontalAlignment="Left"
                    Width="400" Height="50" />
        </Grid>
    </controls:Panorama.Title>
        ...
</controls:Panorama>


Posted in Development, Layout, Tips & Tricks, Windows Phone 7 | Tagged , , , | 3 Comments

Post-event summary of Windows Phone CodeCamp in Latvia

Another great Windows Phone code camp took place on a weekend (between 3rd and 4th of December, 2011) and this time in the lovely capital of Latvia: Riga. Once again there were many talented developers, designers, managers and mentors, who in cooperation have produced initial versions of 9 amazing Windows Phone applications, such as Latvian Name Days, 3 modifications of Alphabet ninja, Rain Radar for Baltic region, Public transport information for Riga, etc. “Public transport information for Riga” application have received more scores than others and announced as a winner although other applications were also very impressive. I hope that all of them will reach the marketplace in a very near future.

Once again I have played two roles: speaker and mentor. This time I have learned even more than I did during the Windows Phone CodeCamp in Estonia, because this time most of the applications were using latest Mango features and were more technically complex. Many applications have used different types of Push Notifications. Some have used socket programming, video brushes for barcode readings, XNA, SQL CE for data storing and many many more interesting features. I must admit that developers in Riga are very skilled, even younger students have shown amazing skills in programming.

Thank you Microsoft, Agu, Jaana, Valdis, Andres, Latvian .NET User Group and all the participants for such a great event!

Posted in Development, Events, Presentations, Tutorials, Windows Phone 7 | Tagged , , , , , , | Leave a comment

Post-event summary of Windows Phone Code Camp in Estonia

I suppose it’s about time for me to write a short post-event summary report of Windows Phone Code Camp where I have participated as a coach and lecturer.

As a lecturer I have delivered two Windows Phone related speeches: first one was about Sensors&Location Services(covering topics like Accelerometer, Gyroscope, Compass, Motion, A-GPS) and second about Execution Model&Storing Data.

Of course, coaching and mentoring were two of the most major challenges for this event. There were a lot of different questions, some of them were really tricky. For the first time in my life I have seen an application developed using Visual Basic.NET. That is definitely something you won’t see every day. Each of the teams have shown a strong passion for Windows Phone platform and bringing their unique ideas to life. Winner application (“Tee Info”, “Road Information”) was using Location Services(GPS) to calculate your current speed and displayed an alert in case you were approaching any of speed cameras on the road driving over the allowed speed limit.

I think that Code Camp was a huge success for our developer and Windows Phone community. I hope that each of the applications will reach the marketplace very soon. I would like to thank all the organizers, participants and fellow mentors for this great event!

Posted in Events, Presentations, Windows Phone 7 | Tagged , , , , , | Leave a comment

Simulating GPS position changes using Reactive Extensions in Windows Phone environment

It has become much easier to simulate GPS position change events having Location tool in Emulator, where you are able to pin positions on a map, but for some Unit Tests and mock services it is important to simulate GPS data programmatically. For this reason you would obviously use Reactive Extensions(Rx). Rx allows you to create Observable interface implementation based on Timer and attach it to position reading method. Bellow is the code I use to generate a GeoPosition with random Latitude and Longitude parameters. If isSimulation variable is set to true then simulation mode is activated, otherwise application uses standard GPS functionality.

private readonly GeoCoordinateWatcher _gcw = new GeoCoordinateWatcher();

private readonly Random _random = new Random();

public GpsSamplePage()
{
    InitializeComponent();

    bool isSimulation = true;
    if (!isSimulation)
    {
        _gcw.PositionChanged += (s, e) => GcwPositionChanged(e);
        _gcw.Start();
    }
    else
    {
        Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(4))
        .Select(x =>
            new GeoPositionChangedEventArgs<GeoCoordinate>(
                new GeoPosition<GeoCoordinate>(DateTime.Now,
                    new GeoCoordinate()
                        {
                            // -90 <= latitude <= 90
                            Latitude = (_random.NextDouble() * 180.0) - 90.0,
                            // -180 <= longitude <= 180
                            Longitude = (_random.NextDouble() * 360.0) - 180.0
                        }

                ))).ObserveOnDispatcher().Subscribe(GcwPositionChanged);
    }
}

void GcwPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    Dispatcher.BeginInvoke(() =>
    {
        // thread safe
        tbLatitude.Text = e.Position.Location.Latitude.ToString();
        tbLongitude.Text = e.Position.Location.Longitude.ToString();
    });
}


Posted in Sensors, Windows Phone 7 | Tagged , , , , , , | 1 Comment

Injecting ViewModels to Views using a custom ViewModelLocator in Windows Phone

In one of my previous posts (IoC for Windows Phone: Ninject I have shown a simple IoC and DI tutorial using Ninject. In this tutorial will be based on previously developed code and extended that with a custom ViewModelLocator to bind ViewModels directly to Views. Hopefully, it will allow you to insert ViewModels with dependencies injected easier and faster for your Windows Phone or Silverlight applications.

Continue reading

Posted in Development, DI, IoC, MVVM, Silverlight, Tips & Tricks, Windows Phone 7 | Tagged , , , , , , | 5 Comments

Windows Phone Code Camp in Estonia

Anyone who has a passion for Windows Phone platform, mobile development is welcome to join me and other WP7 enthusiasts at Tallinna Polütehnikum(Tallinn, Estonia) for 2-day Code Camp on 19-20 Nov. You will have a chance to develop your own Windows Phone application with support from mentors, test it on a real device and win prizes including 1-year MSDN Ultimate subscription. You can develop applications on your own or you can join a team, it is totally up to you.

More information could be found here(in Estonian): WP koodilaager (Eneta)

Posted in Events, Presentations, Windows Phone 7 | Tagged , , , , | Leave a comment

IoC for Windows Phone: Ninject

As I have promised in one of my previous posts, I will spend some time explaining the differences between different Inversion of Control (IoC) supported by Silverlight for Windows Phone. In this post is about Ninject. I will also try to compare several IoC implementations in one of my future articles.

Continue reading

Posted in Development, IoC, Silverlight, Tutorials, Windows Phone 7 | Tagged , , , , , , | Leave a comment

Making a POST call to a HTTPS url using HttpWebRequest

Here is a sample method I’ve used for making a POST(HTTP Method) call to a HTTPS url using an instance of HttpWebRequest class:

/// <summary>
/// Method to make a POST call to a HTTPS url
/// </summary>
/// <param name="url">HTTPS url</param>
/// <param name="requestBody">content for a request</param>
private void MakeHTTPSPostCall(string url, string requestBody)
{
    HttpWebRequest webRequest = WebRequest.CreateHttp(url);
    webRequest.Method = "POST";
    webRequest.BeginGetRequestStream(
        requestResult =>
        {

            using (Stream postStream = webRequest.EndGetRequestStream(requestResult))
            {
                if (requestBody != null)
                {
                    byte[] byteArray = Encoding.UTF8.GetBytes(requestBody);
                    postStream.Write(byteArray, 0, requestBody.Length);
                }
            }
            webRequest.BeginGetResponse(
                responseResult =>
                {
                    try
                    {
                        using (var response =
                            (HttpWebResponse) webRequest.EndGetResponse(responseResult))
                        using (var streamResponse = response.GetResponseStream())
                        using (var streamRead = new StreamReader(streamResponse))
                        {
                            var responseString = streamRead.ReadToEnd();
                            var success = response.StatusCode == HttpStatusCode.OK;

                            // do something here with response...
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                },
                null);
        },
        null);
}

Keep in mind that if your call does not have any content(request body) you still can not skip EndGetRequestStream part(shown bellow), because otherwise you will most likely get a HTTP 404 NotFound exception. Actually, any server-side error translates to a HTTP 404 on
the client.

using (Stream postStream = webRequest.EndGetRequestStream(requestResult))
{
...
}


Posted in Development, Tips & Tricks, Tutorials, Web | Tagged , , , , | Leave a comment

Creating reusable animations programmatically in Silverlight and Windows Phone

As many of you know, I answer a lot of emails regarding Windows Phone development and last week I was asked to show how to create reusable Storyboards with animations programmatically in Silverlight (Windows Phone). Of course, there are plenty tutorials in the internet, but I have decided to create my own. In a nutshell, in this post I am going to create a reusable Storyboard based on DoubleAnimation (for translate transformation), which can be applied for any instance of UIElement.

Continue reading

Posted in Development, Silverlight, Tips & Tricks, Tutorials, Windows Phone 7 | Tagged , , , , | Leave a comment

QA: Changing the Border color of Grid element in Silverlight and Windows Phone

Yesterday I have received the following question by Juhee:

I want to change the gray color of a grid to orange.I was able to change the thickness by changing the margin but do you know how to change the color of the grid? So, for example:

<Grid Background="Black"  Margin="5,5,5,5">
    <StackPanel Width="318" Orientation="Horizontal">
        <StackPanel Width="145" Orientation="Vertical">
            <TextBlock TextWrapping="Wrap" Text="{Binding Text}" FontSize="20"/>
            <Image Source="{Binding Photopath}" Opacity="{Binding Dimness}"/>
        </StackPanel>
    </StackPanel>
</Grid>

If you would like to change the Background color of your grid then, simply, modify Background attribute of the grid (Background=”Black”, as you did that in your code).

If you want to change the color of a Grid’s border color or thickness you have to place your grid inside a Border element. Check my sample bellow:

<Border BorderThickness="5" BorderBrush="Orange">
    <Grid Background="Black"  Margin="5,5,5,5">
        <StackPanel Width="318" Orientation="Horizontal">
            <StackPanel Width="145" Orientation="Vertical">
                <TextBlock TextWrapping="Wrap" Text="{Binding Text}" FontSize="20"/>
                <Image Source="{Binding Photopath}" Opacity="{Binding Dimness}"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</Border>

I hope that answers your question.

Posted in Development, Questions, Silverlight, Windows Phone 7 | Tagged , , , , , , | 2 Comments