Here I will post problems I and my colleagues met and solutions we found.

Tuesday, December 18, 2007

Changing background for selected item in WPF ListBox

When I wanted to change background color for WPF ListBox the first thing I did was creating triggers in the style:

The problem is that it doesn't work. I have to change resources instead. Here is the link that describes it very well.


http://blogs.msdn.com/wpfsdk/archive/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox.aspx

Friday, December 07, 2007

Master Detail Binding in WPF

I spent hours today trying to figure out how to display Master Detail relation in two lists, if I have good old DataSet with Relation between tables. All examples I could find in Google were about objects or XML structures.

What worked is this:

Let's assume we have DataSet with two tables, MasterTable and DetailTable. We also have DataRelation named Master_Detail. The binding in code looks like that:

masterList.IsSynchronizedWithCurrentItem = true;
detailList.IsSynchronizedWithCurrentItem = true;


DataSet dataSet = CreateDataSet1();
DataView dataView = new DataView(dataSet.Tables["MasterTable"]);


Binding binding = new Binding();
binding.Source = dataView;
masterList.SetBinding(ListView.ItemsSourceProperty, binding);


binding = new Binding();
binding.Source = dataView;
binding.Path = new PropertyPath("Master_Detail");
detailList.SetBinding(ListView.ItemsSourceProperty, binding);


Now, let's say we have another relation named "Detail_SmallDetail". We would add following:

smallDetailList.IsSynchronizedWithCurrentItem = true;
binding = new Binding();
binding.Source = dataView;
binding.Path = new PropertyPath("Master_Detail/Detail_SmallDetail");
smallDetailList.SetBinding(ListView.ItemsSourceProperty, binding);

I didn't figure out how to do it in XAML yet.

Saturday, October 20, 2007

GeometryModel3D, DrawingBrush and TextureCoordinates

I tried to use DrawingBrush for GeometryModel3D object.

First, I created very simple object (cube without one side) using simple Blue brush, and I could see it. But when I tried to use DrawingBrush, my object became invisible. Apparently, when DrawingBrush is used, TextureCoordinates property for MeshGeometry3D object have to have correct values, and cannot be empty.

Thursday, October 11, 2007

Timers

Experimenting with timers in WPF I found some interesting differences from Windows Forms.

  1. We cannot use timer from Windows.Forms namespace, which leaves us to Timer from System.Timers or System.Threading namespaces.
  2. Both these timers execute their events/delegates in separate thread, from ThreadPool, which means we cannot directly operate with controls now. Again this is opposite to Windows Forms timer.
  3. Timer from System.Timers object has SynchronizeObject property of ISynchronizeInvoke interface type. However, WPF controls do not support this interface so we cannot use it. Again, this is not the same as for Windows Forms.
  4. WPF controls do not have Invoke methods as Windows Forms controls.
  5. What we can and should use is Control.Dispatcher.Invoke method.

Friday, October 05, 2007

Books

Ok, I am in book reading mode.

1. WPF (Unleashed) by Adam Nathan.
Great book. The reason for this book being so good is the way it's organized. The "main course" of the book is the very well written guide to learn WPF without making it too complicated. And there are Notes and Tips that give you the direction where you should dig to know more. Highly recommend.

2. WCF (Unleashed) by Craig McMurtry.
I am struggling with this book. I am at the beginning of it and at this moment I still have determination to finish it. But it's hard. In opposite to WPF book where complex concepts explained simply, here simple concepts can be understood after reading paragraph two or three times. Disappointment, actually.

3. Expert C# 2005 Business Objects by Rockford Lhotka.
I am in chapter 2 yet, but I am in nirvana reading this book. The subject itself is very interesting to me. I am little bit obsessed with idea of "application frameworks". By this moment, I have no single point of disagreement with the book. And as WPF, the author really tries to explain his concepts and ideas in human language. Highly recommend.

Friday, September 14, 2007

Semicolon in SQL Startup parameters

It took me some time to find that when more than one parameter is used as Startup Parameters in SQL Sever, they should be separated by semicolon rather than space.

For example:
-dC:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\DATA\mastlog.ldf;-T4616

Tuesday, August 14, 2007

Understanding 3d in WPF

When I read about 3d support in WPF in MSDN documentation, I had difficulties with understanding. In fact, whole area of WPF in MSDN disappointed me. Anyway, this link helped me to understand it better. http://blogs.msdn.com/danlehen/archive/2005/11/06/489627.aspx

parseInt surprise

It turned out I couldn't make it with my project. However, I still see some problems where solutions are either not obvious for me from documentation, or I just couldn't find them there. And it could be not even related to .NET. I decided to put them here anyway.

Here is one of them. I developed Gmail notifier plugin for Google Desktop. This was my first and currently the only project in Javascript. One of the problem I had was with parseInt function. It turned out that the function is very smart, and trying to figure out what base should be used. And since I tried to parse month or day from the date, I had leading zeros. That made the function think the base is 8, so numbers '08' and '09' could not be parsed.

Thanks to http://www.faqts.com/knowledge_base/view.phtml/aid/8108