Provide value on ‘System.Windows.Data.Binding’ threw an exception

Today is the second time I receive the exception message: “Provide value on ‘System.Windows.Data.Binding’ threw an exception” when using the WPF DataTemplateSelector.

Problem: Static resources declaration order *matter* !!! So you should not declare the instance of your DataTemplateSelector before actually declaring DataTemplates (see code sample below).

<!-- data template selector NOT HERE-->
<local:CustomDataTemplateSelector
	x:Key="_customDataTemplateSelector"
	FirstDataTemplate="{StaticResource _firstDataTemplate}"
	SecondDataTemplate="{StaticResource _secondDataTemplate}"
	ThirdDataTemplate="{StaticResource _thirdDataTemplate}"
/>

<DataTemplate x:Key="_firstDataTemplate">
	<TextBlock Text="dataTemplate 1"/>
</DataTemplate> 

<DataTemplate x:Key="_secondDataTemplate">
	<TextBlock Text="dataTemplate 2"/>
</DataTemplate> 

<DataTemplate x:Key="_thirdDataTemplate">
	<TextBlock Text="dataTemplate 3"/>
</DataTemplate> 

<!-- data template selector -->
<local:CustomDataTemplateSelector
	x:Key="_customDataTemplateSelector"
	FirstDataTemplate="{StaticResource _firstDataTemplate}"
	SecondDataTemplate="{StaticResource _secondDataTemplate}"
	ThirdDataTemplate="{StaticResource _thirdDataTemplate}"
/>

.NET Task class

Hey! Just to give you a heads up for a new class called Task introduced in .Net Framework 4.

This class, as the name suggests, allows the developer to run a synchronous or asynchronous job in a separate thread. It offers quite a few advantages in comparison with other well known classes like the now old BackgroundWorker like the possibility to cancel a task and the possibility to create sub-tasks and many others. In exchange what you see in BackgroundWorker and you don’t see in Task class is progress reporting. Fortunately this is a functionality that is easily implementable also using a Task class. See this nice post for how to do it. You can also find there an equivalent implementation using BackgroundWorker.

Task class is found inside System.Threading.Tasks namespace. This class and related types are part of a set of public types called TPL (Task Parallel Library) and it is a new programming model introduced by Microsoft in it’s framework mainly for parallel programming.

For more information please visit MSDN page for TPL (Task Parallel Library).

Here’s a simple example (from MSDN) of code showing how you can manipulate a single Task instance:

Read the rest of this entry »

Properties defaults for a Binding object in WPF

Default values for a Binding object used to bind a TextBox. No property has been changed neither on Text nor on the Binding itself. Inside the Binding we can see a custom ValidationRule defined.

Default values for a binding object

Eclipse and PHP headache

I’m a Visual Studio guy.

That being said, I tried to setup Eclipse and php. I just wanted to run and debug the code. Nothing complicated.

1. Try to create a php project and run it

So I downloaded WampServer (which includes Apache, Php and MySQL), then I downloaded Eclipse with php module. Then I created a php project and a php page called test.php. Trying to run it I got the “The webpage cannot be found” error.

2. Try to debug the project

Not being able to even run the project of course debugging wasn’t working either. Setting debug options fired up other errors like:

debugerr_eclipse

(this happens when choosing ‘Test debugger’ in Eclipse Run Configurations options dialog)

After almost a half a day trying to figure that out I still think Visual Studio is the best IDE out there. Of course I’m not giving up and I will make it work in the end.

Generate PDF files in Asp .NET

How can you print documents in PDF format from ASP .NET?

If you have to generate reports then maybe Microsoft Reports or Crystal Reports would be better choices. Microsoft Reports comes with Visual Studio. Crystal Reports was included in Visual Studio until VS2008. If you want to use Crystal Reports in Visual Studio 2010 then go here.

For PDF printing there are several solutions out there.

So…here are a few of the products I ‘googled’ upon:

Read the rest of this entry »

Useful links

TDD Anti-Patterns (by James Carr)

http://blog.james-carr.org/2006/11/03/tdd-anti-patterns/

Discusses a very interesting subject of different abuses that are done by developers in their ‘everyday programming’. Useful to read and definitely useful to apply. Good reading!

(posting date: 2011.02.23)

Web PI just hangs

So if your Web Platform Installer too just hangs at startup before showing up the list of products to install, maybe you have the same problem I ran into a few minutes ago.
Searching the web the following solutions/diagnostics were proposed:
- look in System and Application system event logger – I couldn’t find anything related
- look in %temp%\webpi_launcher.txt for clues – mine was empty
- look in %USERPROFILE%\AppData\Local\Microsoft\Web Platform Installer for clues – yeap that’s it!

Actually in %USERPROFILE%\AppData\Local\Microsoft\Web Platform Installer\logs there are logs which are created each time your start Web PI. And in those logs I saw that Web PI loads data at startup from a cached files located at %USERPROFILE%\AppData\Local\Microsoft\Web Platform Installer.

Solution: just delete all those files located at %USERPROFILE%\AppData\Local\Microsoft\Web Platform Installer and restart Web PI. It worked in my case.

Some good code writing principles

 

KISS Principle – Keep It Simple, Stupid

DRY Principle – Don’t Repeat Yourself

TextBlock vs Label in WPF

A question that most probably every WPF developer asked himself is why have Label and TextBlock controls in WPF?

Doing a simple google search gave this answer:

Label is a more complex control than TextBlock and it has features like access keys (mnemonics) and target controls. So when you hit Alt-Key than the target control get focus (e.g. a label and a textbox).

This difference resides in the fact that TextBlock, even though it is included in Windows.System.Controls namespace, it is not a control. It inherits FrameworkElement class not the Control class. Label on the other hand it inherits from Control class.

For more details I would suggest a post on “John Smith On WPF” blog:

http://joshsmithonwpf.wordpress.com/2007/07/04/differences-between-label-and-textblock/

Make an Fat32 USB disk bootable

Requirements:

1) HP boot disk utility.

2) A folder containing MS DOS system files.

Command line I used:

HPUSBF I:  -FS:FAT32 -V:MYDEV -B:c:\usbdos

‘C:\USBDOS’ folder contains dos system files: command.com, io.sys, msdos.sys

Posted in OS. Tags: . Leave a Comment »
Follow

Get every new post delivered to your Inbox.