Posts Tagged DataBinding

DataBinding ObservableCollection with WPF

Watch out for the code you place in your sub New() of the ObservableCollection – it can cause the WPF designer problems as the designer will attempt to execute the constructor during design time.  If you’re trying to populate the collection from a file based database then the connection string, in some situations, VS 2008 will look in the wrong place for the database.  It appears that using the |Data Directory| prefix for the database causes VS 2008 (RTM) to look in the working directory of VS – rather than the project directory.

Symptoms of this kind of problem are VS reporting:

“Could not create an instance of type ‘abc’. …Window1.xaml 8 3″ and your XAML reference will be squiggily underlined.
A solution to this problem is wraping the constructor of the object implementing the ObservableCollection in a try/catch and swallowing the error (suggested only during the development cycle) or by detecting if you’re in designtime.

A simple way to detect if you’re in designtime with WPF is:

If DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow) Then
  Add(New contact("DesignTime", "Detected"))
Else
  Try
    oContactsTA.Fill(oContacts)
    For Each thisRow In oContacts
      Add(New contact(thisRow))
    Next
  Catch ex As Exception
    Add(New contact("DesignTime", "NotDetected"))
  End Try
End If

3 comments Saturday 24th November, 2007


Recent Posts

a

Tags

AI CF chef cognative processes cognition components DataBinding deployment Development development tips dev tips distributed php distrubuted dynamic filtering evolution filtering data flashdrive frameworks genetics google hosting Katmai NLP ObservableCollection PHP problems with readyboost provisioning ReadyBoost Research SD serverside JS sitemap site stats social evolution SQL 2005 SQL 2008 SQL Server Symfony testing virtual machine Vista Visual Studio 2008 vm WPF xD

The Cloud...

.NET AI Blogroll Compatible Applications Development evolution genetics Internet Microsoft Mobiles MUD's NLP & MT observations Origami other fluff PHP Poetry Research Smarty Symfony tips Vista Visual Studio WCF/Indigo Wireless Technology WordPress world WPF WWF x64

Blogroll

Feeds & Links

Games

NLP & MT

Symfony

VoIP

Meta