Archive for category Uncategorized

Updated WordCloud Component

I’ve updated the WordCloud component and added some documentation that you can find here: http://whydoidoit.com/wordcloud-for-silverlight

The new component supports individual word colouring and word angle.

Leave a Comment

Silverlight AllChildren: find all of the visual children of a FrameworkElement

Our application has some occasions where we need to iterate the entire child tree of a visual component. Not a common thing in many applications, I use it to pass visual states to the sub elements of a tree, but if you need a routine for this purpose then I thought I would post mine here:  


        public static List<T> AllChildren<T>(this FrameworkElement ele, Func<DependencyObject, bool> whereFunc = null) where T : class
        {
            if (ele == null)
                return null;
            var output = new List<T>();
            var c = VisualTreeHelper.GetChildrenCount(ele);
            for (var i = 0; i < c; i++)
            {
                var ch = VisualTreeHelper.GetChild(ele, i);
                if (whereFunc != null)
                {
                    if (!whereFunc(ch))
                    {
                        continue;
                    }
                }
                if ((ch is T))
                    output.Add(ch as T);
                if (!(ch is FrameworkElement))
                    continue;

                output.AddRange((ch as FrameworkElement).AllChildren<T>(whereFunc));
            }
            return output;
        }

The function is an extension method that uses the generic Type to decide on the types of children to return.  It takes an optional “Where function” that can be used to stop iterating down branches of the visual tree – please note that the Where function doesn’t only get passed the Type components, it gets everything so you can stop the recursive operation when you want to.  If you don’t pass the Where parameter then all visual children are returned.  

 

                foreach (var c in panel.AllChildren<Control>((child) => !(child is FdTreeViewItem)))
                {
                    VisualStateManager.GoToState(c, "FlowSelected", true);
                } 

   

, , ,

1 Comment

Finally got my file hosting sorted out!

Why is it that every damn file hoster I try is just rubbish.  Either they don’t work or they put everyone through the wringer to get at the damn file.

Ahh well, sorted now, got my web host configured, so anyone downloading from this blog will be pleased to find there are no longer any hoops to jump through :)

Leave a Comment

Silverlight shared class libraries

I’ve been struggling with the fact that my application really needs shared class libaries and it needs to pass instances of these back and forth with a WCF service running on the back end.  After lots of playing around with data contracts I finally have an elegant solution that uses POCO object serialization and transfers the entities using byte arrays.  The real problem now is the huge size of those serialized objects, wow, DataContractSerializer is wordy as hell – so I’ve stuck a ZIP in the code to reduce the data transmission size but now I’m really on the lookout for a Silverlight serializer that knows what it’s doing via reflection and doesn’t feel the need to write massive descriptor strings on every property – just uses a dictionary of knowntypes and tokens to reduce the size.

If I can’t actually find one of those yet it looks like I may be rolling my sleeves up!  You can find an article here that does an implementation where you write a lot of the serialization logic yourself – that’s going to work for a lot of people but in my app there are so many objects being serialized written by different users it’s too risky to introduce all of the additional coding. My biggest hope is for this project that looks like it might be the right way to go.

Back to the original point: the trick to an elegant, scalable and pluggable implementation of POCO serialization between Silverlight and WCF is to use MEF or write your own type scanner and decorate the types you want to send with an attribute that indicates the type needs to be added to the KnownTypes collection of the serializer.  The built in KnownType attribute only works when you know all of the classes you might want to serialize in advance – not good in the case of a dynamic application, because every time someone wrote a new class you would have to change the WCF definition!

//UPDATE:

Oh well, tried out the serialization library that looked good, unfortunately I need to have my properties serialized not fields, and the project clearly has had that disabled for a reason  - quite a lot of hard to trace errors when I did enable it so I guess it’s back to the drawing board.  Damn.

//FURTHER UPDATE: Another post on this blog lists my solution to this.

, , , , ,

Leave a Comment

Follow

Get every new post delivered to your Inbox.