- Recent
- Popular
- Tags (0)
- Subscribers (1)
- Auto-sizing Canvas for Silverlight and WPFNovember 11
-
One of the first issues I ran into when I was learning WPF was that the Canvas didn't size to its contents. I was attempting to render a graph and I wanted to stick a Canvas in a ScrollViewer and have the scroll area grow as more content was added outside the current bounds of the Canvas. While searching for a solution I noticed on various forums that several other developers were looking for a solution to this problem. At the time I didn't know enough about writing custom layout containers to write my own Canvas and I soon found myself diverted.
Today I work for Microsoft and am partly responsible for Silverlight Charts. Now that I'm rather comfortable writing layout containers I figured I'd spend a few minutes and bang out a Canvas control that provides all the flexibility that I'd always wanted. Ladies and gents I present DynamicCanvas.
In addition to restoring the WPF Bottom/Right properties that are missing from Silverlight's Canvas the DynamicCanvas adds CenterLeft, CenterTop, CenterRight, and CenterBottom properties. In WPF these properties are convenient but not strictly necessary as you can use a multi-binding and a converter to center your objects declaratively. However Silverlight 2 does not support multi-bindings which makes it rather more difficult to ensure that objects will remain c
- Haskell for C# Programmers Part 2: Understanding IONovember 5
-
One of the most difficult things for C# developers to understand about Haskell is the way in which it performs stateful tasks such as IO. In part 1 I explained the difference between methods and pure functions. Pure functions always return the same value if passed the same arguments and don't change the state of the system. C# methods that change state (ex. change a global variable, return a pseudo-random number, write to disk) are considered "impure." In C# we can create both pure functions and methods. In Haskell it is only possible to create pure functions. This might seem strange. After all without impure operations you can't even generate a random number. That would make for a pretty dull poker game eh?
"Who cares about purity?"
Impure programs are a lot like machines with moving parts. Every time you look at them they are in a different state. In contrast pure programs are like machines with no moving parts. They are, on close inspection, just formulas executed by the computer. Want to take a guess which machine is more reliable?
In addition to the benefits of clarity and increased reliability it turns out that compilers can also make certain types of optimizations if they can be sure that code is pure. That's one of the reasons Haskell can be very fast despite the fact that it is such a high-level language.
"That's all well and good but
- Using ImplicitStyleManager and Theme ContainersNovember 3
-
No doubt many of the developers and designers who are exploring Silverlight have had some exposure to WPF. As a result they may be used to relying on implicit styles to ensure their application's have a uniform look and feel. WPF's implicit styling behavior ensures that styles in the resources of an element are applied to their logical descendents. Take the following WPF XAML snippet for example:
<StackPanel>
<Border>
<Border.Resources>
<Style TargetType=“{x:Type Button}">
<Setter Property="Foreground" Value="Green"/>
</Style>
<Style TargetType=“{x:Type TextBlock}">
<Setter Property="Foreground" Value="Green"/>
</Style>
</Border.Resources> - ImplicitStyleManager: Under the HoodOctober 30
-
In this post I'll delve into the functional programming techniques that were used to develop ImplicitStyleManager. If you want to know how to use ISM to add fresh new looks to your Silverlight applications take a look at this post.
ISM is a great candidate for a functional solution. There is no unpredictable user inputs to muddy the waters which is rare for a control. Following best practices I did my best to separate the functional task of generating a sequence of all elements to be styled from the imperative task of applying the styles to those elements. I thought I'd share it with you because it's yet another example of how powerful and flexible functional programming can be.
Walking the Tree
The code required to generate the sequence (IEnumerable<T>) of tree nodes is actually very simple. It traverses the logical tree and returns a flat sequence of elements, their merged dictionaries, and the style applicable to them (if found).
BaseMergedStyleDictionary initialDictionary = GetMergedStyleDictionary(element);
// Create stream of elements and their base merged style
// dictionaries by traversing the logical tree. - Building an Observable Model in SilverlightOctober 29
-
Now that Silverlight 2 has been released .NET web developers can begin writing rich Internet applications in languages like C# and VB.NET which they know and love. However if you have spent the last few years developing web applications using ASP.NET you may have developed certain habits that will not serve you well in when writing Rich Internet Applications. Undoubtedly one of those habits is avoiding state. Sure you could always use the view state or worse, the session state to store information across page loads. However it's generally advisable to use as little state as possible to maximize the scalability of your ASP.NET applications. It's important to unlearn this behavior now that Silverlight 2 has been released.
Repeat after me: "State is good."
Client state, this is. Modern hardware is fast and memory is cheap. Part of building rich Internet applications is leveraging all that juice to transform what users expect from web applications.
Of course this calls for a very different set of design patterns than the ones we use to build stateless applications. In the RIA world it is no longer necessary, nor efficient, to destroy and recreate objects all the time. However if we keep objects around a long time we run the risk that they will get into inconsistent states. An example of this problem is an application not updating the status bar and disabling the "Save" menu item when a new file is loaded in a text editor applicat
