Skip to content

DataBinding in WP7–The Quick and Easy Way


Here is something I found for those who wish to perform databinding on a  List Box using ItemsSource using static data the quick and easy way!

I started by added a static reference to the MainViewModel in the App class of App.xaml.cs

 private static MainViewModel viewModel = null;

 public static MainViewModel ViewModel
 {
  get
  {
  // Delay creation of the view model until necessary
  if (viewModel == null)
   viewModel = new MainViewModel();
  return viewModel;
  }
 }

My two lists in the MainViewModel class of MainViewModel.cs looked like this:

 public MainViewModel()
 {
  // Insert code required on object creation below this point
  Items1 = new ObservableCollection<ItemViewModel>() {
  new ItemViewModel() { LineOne = "runtime one", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu", },
  new ItemViewModel() { LineOne = "runtime two", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus", },
  new ItemViewModel() { LineOne = "runtime three", LineTwo = "Habitant inceptos interdum lobortis", LineThree = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent", },
  };

  Items2 = new ObservableCollection<ItemViewModel>() {
  new ItemViewModel() { LineOne = "runtime one", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu", },
  new ItemViewModel() { LineOne = "runtime two", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus", },
  };

 }

 public ObservableCollection<ItemViewModel> Items1 { get; private set; }

 public ObservableCollection<ItemViewModel> Items2 { get; private set; }

Now I changed the initialisation of DataContext in MainPage.xaml.cs to reference the static object

  if (DataContext == null)
  DataContext = App.ViewModel;

Removed the direct reference to the Items1 list in MainPage.xaml so it only had the binding

  <ListBox x:Name="ListBoxOne" ItemsSource="{Binding}" MouseLeftButtonUp="ListBoxOne_MouseLeftButtonUp" Style="{StaticResource PhoneListBox}">

And now I can use my conditions check to set the ItemsSource using the following code in MainPage.xaml.cs

  ListBoxOne.ItemsSource = App.ViewModel.Items2;

How to install Microsoft SQL Server Management Studio on desktop


A common dilemma is to see that you have MS SQL Server 2008 installed but not the Microsoft SQL Server Management Studio on your PC, to do it go to : –

http://www.microsoft.com/download/en/details.aspx?id=7593

This link installs the Express edition which does essentially everything you need associated with MS Server 2008, as it says its an integrated environment for accessing, configuring, managing, administering, and developing all components of SQL Server 2008!

sqlserver2008

What I found also is that the installation file wouldn’t install it automatically, you have to select New Install on the SQL Server 2008 Setup, and manually tick the one and only (yes one) shared feature which is Management Tools – Basic to install the Microsoft SQL Server Management Studio on your PC Desktop. Wait for 10 minutes. Voila!

Also if you are programmer, you want to test certain database files for local use in Microsoft Visual Studio 2010, and that means that you want to be able to attach the database on another server (well locally on Visual Studio 2010), then this is what you can do:

  1. Detach the database (right click the database and click Detach)
  2. Copy the mdf and ldf files to your backup location
  3. Attach the database (right click Databases and click Attach)

More information on checking if an element exists in JQuery


The simplest mistake sometimes costs several hours of debugging. One of these is checking if the target exists before trying to apply some changes to/using it.

How to check if element in DOM exists, i.e. if the selector $(‘.some_class’) is not empty?

The simplest:

if ($('.some_class')) {

//some action

}

will not work!

The correct condition uses the .length function:

if ($('.some_class').length > 0) {

//some action

}

Note no brackets after .length.

How to check if JavaScript object’s property exists?

This is tricky, as there are two types of properties: own properties and prototype properties. Not going into details, we can assume, that own properties are the one that are for example serialized by JSON, and prototype properties are the one that can be empty or not, but are given in the object’s definition.

So, in most cases you want to check if the own property exists for the given object. This can be obtained using the hasOwnProperty() method:

if (the_object.hasOwnProperty("name)) {

//some action

}

If you only want to check whether there is the prototype property, you may use in operator to determine the existence of the property:

if ("name" in the_object)) {

//some action

}

How to Swipe gesture on JQuery Mobile}


 

Here is the code for how to do swipe gesture in JQuery Mobile, here it checks the body tag, and sets a “live” event to detect the swipe gesture, and shows an alert.

  $("body").live('swipe', function() {
         alert("swiped");

}

Bug fixed for Samsung Galaxy SII


For some reason when viewing a dialog page for JQuery Mobile using Android 2.22 on Samsung Galaxy SII, if you close the dialog box when opening from main page, such that it goes back to the main page again, and click a submit button, on the application I am writing it goes back to the dialog page which is not what I wanted. That is a real surprise considering its the latest Android device, and hasn’t been thoroughly tested on the latest version with JQuery Mobile. The long fix is to manually remove the submit button, and manually append the same button with the ID, and with the binding click event from the main JS file, which means copying the right functions.

Sorted out IIS 7.0 Issues and fixed most of AtomSite blog for mashupweb.co.uk


Finally, on Friday and today I have fixed at what it seems a simple error as to why I couldn’t log in to IIS 7.0, having trying to reinstall AtomSite on Web Platform Installer which is the supposed official program wizard from Microsoft to install new programs for IIS.

However, the same error message kept on appearing as shown: –

webplatforminstaller3

The message had read Filename: \\?\C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

Line Number 141

Error: Configuration section not allowed in a <location> tag.

I had even attempted to reinstall the IIS 7.0 components as shown in the screenshot below, by removing the roles for Web Server, but to no rprevial, the same error had shown up again the following day!

DasBlog2

After an hour the next day of baffling how to solve it but trying to install new programs like WordPress, the same error had shown. The fact was that extra tags had been added in the machine.config on that line which was a fatal mistake, it had something to do with allowpermissions and allowoverrides added into the line. Fact: don’t tamper with the file at all!

IIS 7.0 ran perfectly after that without having to ask you to log in.

On some good fortune as well, I solve part of the problem as to why AtomSite wasn’t working properly with the blog entry links, it had something to do with the the with the theme settings in Administration, so switching all to Blue setting in the same theme for www , blog, and all other entries made it work.

Bank Holiday Special Adding Page Transitions quickly in WP7


As I am on the train during this Bank holiday, I wanted some quick XAML code to add a page turnstile page transition between swiitching pages, which is quick and effective at less than 350ms, so that is user friendly, and delights the user experience.

Here’s how you add the XAML at the top if the declarations for backwards and forwards in the navigation in transitions:-

Then add this for where to transition to:-

Compile and you notice this hasn’t been done in effective, to make it work, you need to go the initialisation code which maps to the application really closely.

Under the

InitializePhoneApplication()method replace the following:

//RootFrame = new PhoneApplicationFrame(); this has been commented out
RootFrame = new TransitionFrame();