Thursday 16 February 2012

Control Templating in WPF

Here's an old, but on-topic, blog post, summarising Control Templating and the Visual Tree concept in WPF.

Going Native 2012

"C++ is two halves: Core language: your pointers, integers, floating point and Standard Library, on which users actually build their programs". C++ is still the best choice for high-performance code that needs to be ROBUST. Check out these talks. Also, for comparison, check out Anders' C# talk on C# Five-Oh and writing "asynchronous Metro applications".

Saturday 11 February 2012

What are DEPENDENCY properties in Silverlight?

Remember, that Silverlight is a mere microcosm of a bigger library known as the behemoth WPF. So when we discuss the Silverlight property system what we are really talking about it just a small subset of what might be known as the "WPF" property system. So there you go.

The Silverlight property system (TM) provides ways to EXTEND the CLR PROPERTY SYSTEM. You all heard that, right? We are EXTENDING THE CLR PROPERTY SYSTEM. Great. A dependency property is, quite simply, a property that is backed by the SL property system is most appreciatingly known as a DEPENDENCY PROPERTY.

Dependency properties, as their name suggests, are fundamentally about dependencies. We want a property to AUTO-COMPUTE based on the value of other properties. In this way, we might think of dependency properties, as nothing more than the oh-so-ordinary appellation called "dependent" properties, but we call them more fancy names, like "dependency" properties. "Dependency" does sound a lot cooler than "dependent".

Some rules of the game: a dependency property must be on a DependencyObject. They are usually public static and readonly members.

Please explain the WPF concept of DATA TEMPLATING

A very good question. Now you are understanding what it takes to be a WPF master. You CAN get away without understanding this concept, but you will NOT be a master. It is part of the knowledge base relating to "WPF Styling and Templating".

Practical, simple example of DATA TEMPLATING. You have a ListBox and want to configure how items are displayed in it. You can define a DATA TEMPLATE within the ITEM TEMPLATE tag (ListBox.ItemTemplate) within the "SCOPE" of the ListBox. The formatting declarations would then appear within a tag entitled <DataTemplate>. We can also define the DataTemplate within the Resources section of XAML to make it a reusable object. The DT defines HOW DATA APPEARS including appropriate bindings for textual information, borders etc.

The Healing Power of Programming = Less Target and More Journey

Programming is a practical and special skill. Once a specialist technique is mastered it can be re-used. Programming is time-intensive in terms of learning and presents a moving target. Sometimes programmers feel as if contending with a landslide as development infrastructure changes under their feet. More effort seems needed to achieve the same results achieved previously with less effort. But this is the learning cycle. New, more powerful, more general abstractions arrive with the ultimate aim of empowering you the programmer - not to take your freedoms away. Case in point is the evolution of the DataGrid or the evolution of DAO, ADO and ADO.NET. New paradigms mean old abstractions may at times need to be revamped totally to fit the new abstraction. People's minds need to be reformulated to orient themselves with the new paradigm. This requires fluid adaptation and tai-chi like re-harmonisation skills. It is like the separation of continents or coming or going of an Ice Age, no less. It may take time and so patience, and persistence too, is necessary. The healing power of programming relies on acceptance and enjoyment of the process of change, not fighting it, not resenting it, but appreciating it. Focus less on the target, though keep mindful of it, and focus more on the incredible learning journey and the learning process - you will enjoy it more. Failure to hit the target (due to necessary time spent learning and re-adapting to the new development landscape) should not be a source of frustration, though often is as ego enters and the anti-programming devil says: "why is this taking longer than what it should". Answer: Adaptation. Understand, appreciate and acknowledge. This is part of the healing power of programming. The commercial animal must be mitigated by the absolute acceptance of transitional learning phases - the tiger must relearn how to hunt.

Silverlight's DataGrid Class - The Third Incarnation of DataGrid

The DataGrid, like Microsoft's data APIs, is in a state of constant evolution. "Nous avons vu" le DataGrid of WinForms fame, followed by DataGridView (recall for one moment the software built in those paradigms), and now behold the DataGrid of Silverlight and WPF (formerly from WPFToolkit.dll). It is also known (via it's fully qualified namespace admonition) as System.Windows.Controls.DataGrid. It's XAML opening tag is <sdk:DataGrid>. Come, let us learn to think in DataGrid (la nouvelle DataGrid rather than Winforms DataGrid of yore)!

Let us begin with an elementary question. How doth one define the columns of la nouvelle DataGrid? Answer: via DataGridTextColumn, or via DataGridTemplateColumn.
To understand the latter, one must know about DATA TEMPLATING (fundamental WPF concept - so fundamental one cannot claim to be a WPF master-programmer without a detailed knowledge of the same, much like the mega-foundational concept of DEPENDENCY PROPERTIES. We will repeat now the WPF mantras once more for consolidation: DATA TEMPLATING. DEPENDENCY PROPERTIES. YEAH. Such great concepts.

Formatting tricks such as alternating row backgrounds, ability to show and hide grid-lines and scroll bars are all part of the standard DataGrid "bag of tricks". Let the GUI be with you. Always.

Resharper Stinks

Resharper is a very good concept and aims to do wonderful things (similar to IntelliJ in the Java world). It can even assist you in writing code by suggesting subtle and smart improvements. But, the keyboard shortcuts can get confused with the "natural" Visual Studio shortcuts and it can make your IDE extremely slow, particularly if you are working on a large codebase and have other, more essential, add-ins installed in your Visual Studio environment.

The Last Word in Word Wrap Options in WordPad

There's more than one type of "word wrap" living in View->Options in WordPad. These are: No Wrap, Wrap to Window (preferred) or Wrap to Ruler. Basically, you want "Wrap to Window" so that word wrap adapts to resizing of the window.