Stock Data Visualization Using Silverlight

I’ve written an article on CodeProject on visualizing live and historic stock data using Silverlight. In the article I’m presenting a pretty generic way of fetching, parsing and displaying the stock data.

The structure of the article is as follows:

Read the full article and download the source code on Codeproject: Visualizing Live and Historic Stock Data Using Silverlight

10 Things Developers Will Love About Silverlight

On the Silverlight Firestarter Scott Guthrie gave a preview of the new features being developed in Silverlight 5. I’ve written an article on the 10 most important new features Silverlight developers should be excited about. These are the following:

  1. Debug Data Binding Expressions by Using Breakpoints in XAML
  2. Animations Made Easy with Transitions
  3. Navigating Up the Visual Tree in Bindings using RelativeSource and Mode=FindAncestor
  4. Binding View Events to the ViewModel Using Custom Markup Extensions
  5. Changing Styles Runtime By Binding in Style Setters
  6. Networking No Longer Happening on the UI Thread
  7. Vector Based Printing
  8. HTML Content and Additional Permissions Within Trusted Silverlight Application
  9. 3D API
  10. Smaller Enhancements: Text Clarity and Performance Improvements

You can read the full article with details on all of these features on my Visiblox blog.

Manipulating Styles At Runtime in Silverlight

I’ve been writing a 4 part series on everything (I think) is worth knowing about styles in Silverlight. The previous parts were Silverlight Styles: an Introduction, Silverlight Styles: Advanced Topics and Silverlight Styles: Further Advanced Topics

The final part of the series is ready and it covers the following topics:

  • Modifying Styles Runtime: the IsSealed Property – modifying the Setters of a Style can only be done if the IsSealed property is set to false and this property is set to true as soon as the style gets applied to an element in the visual tree.
  • Cloning Styles – because sealed Styles can’t be modified, one needs to clone them to be able to manipulate them. I’m providing example code on how cloning of a Style can be done.
  • Merging styles runtime – I’m showing two ways of merging existing styles programatically, both using the BasedOn property of Style as well as just copying Style setters.

You can read the detailed article and download source code for examples on my Visiblox blog – I hope you’ll find it useful.

Getting Started with WP7 Development: Learning Siverlight

This post aims to present a structured collection of resources for developers wanting to get started developing for Windows Phone 7 in Silverlight, but don’t have any Silverlight or WPF experience. I’m also aiming this post at peopleĀ  who’ve started developing for WP7 without too much WPF/Silverlight experience and would like to learn more about the framework to move on.

Why Silverlight?

Developing for Windows Phone 7 can be done using two frameworks: Silverlight and XNA. XNA is a framework targeting game development. Those who are looking to develop either games or graphically intensive applications are advised to use that framework.

Silverlight, on the other hand started off as a web application framework, a “web” light version of Windows Presentation Framework (WPF), the successor of Windows Forms. Microsoft decided to support Silverlight as the other application development framework on Windows Phone 7 next to XNA, specifically version 3.0 with some extra libraries. It’s safe to say that if one’s goal isn’t game development, the obvious (and easier) choice is to develop applications in Silverlight for WP7.

What is Silverlight?

Silverlight is a similar framework to Adobe Flash, allowing the developer to create applications that manipulate media, are interactive all built on the .NET platform. .NET developers will be familiar with lots of the libraries used, however Silverlight introduces several new concepts and libraries. With Out Of Browser support and Windows Phone 7 development announced, Silverlight is no longer just a web framework, but more an application development platform.

Some useful resources on understanding what Silverlight is:

Developer tools

Silverlight development can be done with Visual Studio 2008 and upwards, I’d recommend using Visual Studio 2010 – a free, express version is available for use. Expression Blend is an additional tool that makes creating the UI much easier.

If you’re planning on doing WP7 development, download the developer tools for WP7 which will either install the expression version of Visual Studio 2010 and a phone version of Expression Blend or if VS and Expression Blend are already installed, it will just add the new supported project types and the emulator.

Understanding how Silverlight Works

There are some key areas anyone from an OO background needs to understand to be able to develop with Silverlight.
Read More…

Problems when re-assigning a PathGeometry in Silverlight

Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c03/h02/mnt/50561/domains/ on line 76

I wasn’t planning in submitting (yet) another workaround for a Silverlight bug, but I stumbled across (yet) another annoying issue that causes no problems in WPF, but results in a exception being thrown in Silverlight. It definitely seems like another Silverlight bug still present in Silverlight 4.

The problem

I was building Paths by re-using a pre-built collection of PathGeometries. However when re-assigning a PathGeometry to another Path like this:

Path path1;
Path path2; // These paths are in the visual tree
// Create a PathGeometry with some points
var points = new PointCollection();
points.Add(new Point(100, 0));
points.Add(new Point(100, 100));
points.Add(new Point(0, 100));
var pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(0, 0);
pathFigure.Segments.Add(new PolyLineSegment() { Points = points });
var pathGeometry = new PathGeometry();
// Assign this PathGeometry to both Paths
path1.Data = pathGeometry;
// No you don't you get an ArgumentException
path2.Data = pathGeometry;

When trying to re-assign this PathGeometry, an ArgumentException was thrown with the message Value does not fall within the expected range. After googling around it turned out others have come across this issue back in mid 2008. This issue is only present in Silverlight, not WPF, which definititely suggests it is a bug.

However, having received a completely meaningless exception, I decided to dig deeper to at least try to understand what went wrong and find a workaround.
Read More…

Disappearing Style Setters in Silverlight 3 and WP7 – fixed in Silverlight 4

I’ve come across a really annoying bug in Silverlight 3 that seems to be fixed in Silverlight 4, but still present in WP7. When creating a Style object in runtime, then setting that as the Style of an element in the visual tree, the Value properties in the Setters of the original Style are set to null!

The problem

I’ve come across this issue because I was trying to clone styles with the following extension method:

public static Style Clone(this Style style)
    if (style == null)
        return null;
    Style clonedStyle = new Style(style.TargetType);
    clonedStyle.BasedOn = style.BasedOn;
    foreach (Setter setterToCopy in style.Setters)
        clonedStyle.Setters.Add(new Setter()
            Property = setterToCopy.Property,
            Value = setterToCopy.Value
    return clonedStyle;

As you can see, this clone method is not doing anything complicated: it is simply iterating through the Setters of the Style and creating new Setter instances with the Property and Value of the original Setters – basically deep cloning the Style itself.

The issue in Silverlight 3

When I did clone a Style that had been created on the fly and had been assigned a the Style of an element, the values of Setters magically were set to null in Silverlight 3. The problem is visualized using the following simple code:
Read More…

Setting the StrokeDashArray using a Style in Silverlight

I’ve recently ran into an issue: I wanted to draw an element with a dashed stroke using a Style I’ve created on the fly. To my surprise I couldn’t.

The Problem

The type of the StrokeDashArray (that is defined on Shape) is a DoubleCollection. So naturally I tried setting a DoubleCollection instance as the Value of the Setter on the Style I created:

Style ellipse2Style = new Style(typeof(Ellipse));
// Setting a DoubleCollection as the Value of the Setter for StrokeDashArrayProperty doesn't work!
ellipse2Style.Setters.Add(new Setter(Ellipse.StrokeDashArrayProperty,new DoubleCollection() { 2, 2 }));
Ellipse2.Style = ellipse2Style;

Read More…

Styles in Silveright – Data Binding, Runtime Declaration and Further Advanced Topics

I’m writing a 4 part series on everything (I think) is worth knowing about styles in Silverlight. The previous parts were Silverlight Styles: an Introduction and Silverlight Styles: Advanced Topics.

The third part of the series is ready and it covers the following topics:

You can read the detailed article on my Scott Logic blog – I hope you’ll find it useful.

The final part of the series will explore manipulating styles in runtime.

Styles in Silverlight – Advanced Topics

I’m writing a 4 part series on everything (I think) it’s worth knowing about styles. In the second part of the series (following the previous one Styles in Silverlight – an Introduction) I’m covering the following topics:

  • Re-Using Styles for Different Types: the TargetType of the Style can be a parent type of the target object as long as it only sets properties of the parent type.
    So for example the Fill property of both an Ellipse and Rectangle can be styled by using a Style that’s TargetType is set to Shape (as both Ellipse and Rectangle inherit from Shape)
  • Inheriting Styles using the BasedOn property: Styles can be inherited from one another using the BasedOn property. Single inheritance is supported and the depth of inheritance is not limited.
  • Implicit styling: Implicit styles allow defining a default style for all instances of a given type within the scope of the control. This feature has been introduced in Silverlight 4.
  • Style Precedence: Styles are only applied to a property if that property is not animated, has no local value set and has no value set in a template. This precedence is the same as the dependency property precedence.
  • Style Setter Precedence: setters specifying the value of the same property may be declared within the same Style. The last one of them has the highest precedence and will be used.
  • You can read the (much more detailed) full article on my Scott Logic blog. The next part of the series will cover further advanced topics such as using Styles in code behind and exploring the relationship between styles and dependency properties from a practical perspective.

Styles in Silverlight: an Introduction

I’m writing a (planned) 4 parts series on everything I think it’s worth knowing about styles in Silverlight. The first part is ready and it covers the following topics:

You can read the (much more detailed) full article on my Scott Logic blog. This part has meant to be an introduction, the next parts will dig into more advanced Style usage scenarios.

1 2 3  Scroll to top