So there was a bunch of xml files that I wanted to understand better based on trends and i thought i'd build a silverlight app to render the data. I could have created a program to generate the data in text and just plot them in Excel, but then i thought i should exercise my Silverlight mind for a bit.
Ingredients:
* xml sources
* a styled rectangularBar control// i basically drew a rectangle, changed the fill, right-clicked -> make control
* a named StackPanel i in the main silverlight component
1. using linq, read in and process the data from your bunch of XMLs. In my case, i read each file, concatinated everything, grouped by an attribute, and make the count an attribute. Package it all up in a method called readXML that will return a list of your desired objects / form
2. Blend the rectanglularBar to make it a bit more pretty.
3. Add a named StackPanel to your main canvas:
<Canvas x:Name="LayoutRoot" Background="White">
<StackPanel x:Name="panel"></StackPanel>
</Canvas>
4.in your Page.xaml.cs (codebehind, append the next lines to after the loaded event InitializesComponent():
var msgxml = readXML(); //reads from XML &sorts your data
foreach (var x in msgxml)
{
var y = new StackPanel() { Orientation = Orientation.Horizontal }; // created a new horizontal
//StackPannel to manage the layout of the next two components
y.Children.Add(new TextBlock() { Text = x.datestamp, Width = 100, FontSize = 8, Height=10 });
y.Children.Add(new bar() { Width = x.value});
this.panel.Children.Add(y); //add the Panel born out of Visual Studio t
//e panel born out of expression blend
}
this was how it looked like. Blend it up so you can make it much prettier! I'm really loving LINQ and XAML right now.
P.S. Yes, this could have also been easily done with data binding but my brain was too tired to think. I still don't have the layouting part nailed down yet. Still have a LOT to learn…
p.p.s. yes, i know, there is something off with my sorting.. i only sorted by datevariable[0], i.e., first character. :p I was also too lazy to think about how to sort dates read from xml ..
