Click here to Skip to main content
15,887,746 members
Articles / Mobile Apps / Windows Phone 7

Property Finder – a Cross-Platform Xamarin MonoTouch Mobile App

Rate me:
Please Sign up or sign in to vote.
5.00/5 (17 votes)
3 Jan 2013CPOL19 min read 79.9K   1.2K   48  
A look at how Xamarin MonoTouch allows you to create cross-platform applications, using the native C# / Silverlight for Windows Phone and C#, via Xamarin MonoTouch, for iOS.
using System;
using PropertyFinder.Presenter;
using Microsoft.Phone.Controls;
using PropertyFinder.Model;
using System.Collections.Generic;
using System.Windows.Input;
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Controls;

namespace PropertyFinder
{
  public partial class PropertyFinderView : PhoneApplicationPage, PropertyFinderPresenter.View
  {
    private PropertyFinderPresenter _presenter;

    // Constructor
    public PropertyFinderView()
    {
      InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
      base.OnNavigatedTo(e);

      if (e.NavigationMode != NavigationMode.Back)
      {
        var source = new PropertyDataSource(new JsonWebPropertySearch(new MarshalInvokeService()));
        var geolocationService = new GeoLocationService();

        var statePersistence = new StatePersistenceService();
        PropertyFinderPersistentState state = statePersistence.LoadState();

        _presenter = new PropertyFinderPresenter(state, source,
          new NavigationService(NavigationService), geolocationService);
        _presenter.SetView(this);
      }
    }

    public string SearchText
    {
      set
      {
        searchText.Text = value;
      }
    }

    public event EventHandler SearchButtonClicked = delegate { };

    public event EventHandler MyLocationButtonClicked = delegate { };

    public event EventHandler<LocationSelectedEventArgs> LocationSelected = delegate { };

    public event EventHandler FavouritesClicked = delegate { };

    public event EventHandler<SearchTextChangedEventArgs> SearchTextChanged = delegate { };

    public event EventHandler<RecentSearchSelectedEventArgs> RecentSearchSelected = delegate { };

    public void SetMessage(string message)
    {
      userMessage.Text = message;
    }

    public bool IsLoading
    {
      set
      {
        loadingIndicator.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
        searchText.IsEnabled = !value;
        buttonMyLocation.IsEnabled = !value;
        buttonSearchGo.IsEnabled = !value;
      }
    }

    private void ApplicationBarFavourites_Click(object sender, EventArgs e)
    {
      FavouritesClicked(this, EventArgs.Empty);
    }
    
    private void ButtonSearchGo_Click(object sender, RoutedEventArgs e)
    {
      SearchButtonClicked(this, EventArgs.Empty);
    }

    private void ButtonMyLocation_Click(object sender, RoutedEventArgs e)
    {
      MyLocationButtonClicked(this, EventArgs.Empty);
    }

    private void SearchText_TextChanged(object sender, TextChangedEventArgs e)
    {
      SearchTextChanged(this, new SearchTextChangedEventArgs(searchText.Text));
    }
    
    public void DisplayRecentSearches(List<RecentSearch> recentSearches)
    {
      if (recentSearches == null || recentSearches.Count == 0)
      {
        recentSearchesContainer.Visibility = Visibility.Collapsed;
      }
      else
      {
        recentSearchesContainer.Visibility = Visibility.Visible;
        recentSearchList.ItemsSource = recentSearches.ToArray();
      }
    }


    public void DisplaySuggestedLocations(List<Location> locations)
    {
      if (locations == null)
      {
        locationsContainer.Visibility = Visibility.Collapsed;
      }
      else
      {
        locationsContainer.Visibility = Visibility.Visible;
        locationsList.ItemsSource = locations;
      }
    }

    private void Button_LocationClick(object sender, RoutedEventArgs e)
    {
      FrameworkElement fe = sender as FrameworkElement;
      Location location = fe.DataContext as Location;
      LocationSelected(this, new LocationSelectedEventArgs(location));
    }

    private void Button_RecentSearchClick(object sender, RoutedEventArgs e)
    {
      FrameworkElement fe = sender as FrameworkElement;
      RecentSearch recentSearch = fe.DataContext as RecentSearch;
      RecentSearchSelected(this, new RecentSearchSelectedEventArgs(recentSearch));
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Scott Logic
United Kingdom United Kingdom
I am CTO at ShinobiControls, a team of iOS developers who are carefully crafting iOS charts, grids and controls for making your applications awesome.

I am a Technical Architect for Visiblox which have developed the world's fastest WPF / Silverlight and WP7 charts.

I am also a Technical Evangelist at Scott Logic, a provider of bespoke financial software and consultancy for the retail and investment banking, stockbroking, asset management and hedge fund communities.

Visit my blog - Colin Eberhardt's Adventures in .NET.

Follow me on Twitter - @ColinEberhardt

-

Comments and Discussions