Saturday, 2 October 2010

Simple rules to remember binding business objects to UI in xaml in .Net 4.0

A post for those who are novice in xaml, binding and .Net 4.0

Remeber that
1. variables cannot be bind in xaml, only properties, so when we write in xaml something like
Text="{Binding MyVar, Mode=TwoWay}" 

we need to remember to write declaring the classs: instead of


Public MyVar as integer

the following

Public Property MyVar as integer

although

2. You will need to push a notification if you want UI to be updated updating the business object, so use OnPropertyChanged (link) and so writting the full notation (with Get and Set) instead of the short notation we seen above.

3. Don't forget that you either need to rebind lists, or use instead of simply collections like lists and dictionaries an observablecollection etc (link)


Slightly more advance
1. Don't foget that you can use converters binding a property to UI to represent, for example, a boolean value as a picture


<controls:ChildWindow.Resources >
        <loc:RO_FavImageTypeConverter  x:Key="FavConverter" />
    </controls:ChildWindow.Resources>
....

<Image Source="{Binding Favorite, Converter={StaticResource FavConverter}}"/>



Public Class RO_FavImageTypeConverter
  Implements IValueConverter
 
  Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As Globalization.CultureInfo) As Object _
  Implements System.Windows.Data.IValueConverter.Convert
 
    If value Is Nothing Then Return Nothing
    Dim bIsFav = DirectCast(value, Boolean)
    If bIsFav Then
      Return Utility.ImageHelper.GetImageSource("Resources/favor_yellow.png")
    Else
      Return Utility.ImageHelper.GetImageSource("Resources/favor_grey.png")
    End If
 
  End Function

PS: you can easily find in net how to apply the converter in xaml. Besides Utility.ImageHelper.GetImageSource is just illustrative - you will need to write your own code

2. Notice that you can use converter parameters. For example:


Text="{Binding Amount, Mode=TwoWay, Converter={StaticResource nmbFormat}, ConverterParameter='n0'}"


but be aware that nature of them is quite static. I mean that you can pass (bind) a property to that, but unfortunately you cannot bind two properties in the effective two way interaction.

Consider for example a simple case: you have a class, which contains an amount and a format to be applied on the amount in UI. you can bind Amount as above, but then you bind the number format, as the parameter is static. OK, you can change it by using the valueconverter as in the item 1 above, to get the entire instance of the class into the convertion function to read both amount and the number format, but then you will lose the two way nature of binding: the convert back will get a number enter, for example, into a text box, but were after convertion it will go? into the entire class? obviously it will not work any longer since you have no reference to the instance to which the inputted property should be placed to. If two way need to be working bind a simple property to make it automatically routed to the right places within the binded instance to be updated following UI update.

Saturday, 4 September 2010

Simple conclusions from P!=NP battle

All this battle around P!=NP paper can give to an ordinal student a very important hint.

It is nearly clear that there will be a huge demand for algorithms considering NP problems and inventing algorithms that can solve it faster - obviously not as fast as a P problem ... but each, even simple improvement can lead to a huge improvement (in total) on such complex tasks. Besides we still will have to consider
1. Heuristic approaches as those will still be demanded
2. Finding and isolating classes or subclasses of tasks (problems, graphs) which can be solved in P

Tuesday, 24 August 2010

A post on the scheduling problem

Here is an extremely motivating post about the scheduling problem for beginners with a background in math. Clearly stated easiness for small and ordinal problem and complexity for large scale problems or those, which have different kinds of restrictions. Actually it also refers to this paper, which should be the next step getting into the scheduling problem.

Personally I think it is quite an opportunity for writing a master work for those who hasn't decided yet on a title of their thesis. A lot of work-places has such problems (hospitals, educational centers etc) so it can be treated within the organisation specific restrictions set and so be analytic as well.

Saturday, 14 August 2010

End of story II

In continue the previous story. The worst thing about that fact is that you cannot really rely on Google since the technology their are offering on the market can be closed at any moment. They are so new, so modern and so risky to follow.

Here is a short story of such fact a Google graveyard.

Thursday, 5 August 2010

End of story

A quickly ended history of one well-known and widely marketed technology - Google wave.

Wednesday, 28 July 2010

Another interesting topic for a master work

Here is another, interesting, unusual and for some people risk-free theme for a master work in SE.

One more interesting article on the same topic

Saturday, 24 July 2010