<Usercontrol X: class = "silverlightexcel. Page"
Xmlns = "http://schemas.microsoft.com/client/2007"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Width = "490" Height = "298">
<Grid X: Name = "layoutroot" background = "white">
<! -- Exported with paste2xaml and ab2d. readerwmf. See http://www.wpf-graphics.com/for more WPF tools. -->
<Canvas>
<Polygon points = "5, 5, 5,293, 485,293," fill = "# ffffffff"/>
<Polygon points = "87,59 87,251 470,251, 59" fill = "# ffffffff"/>
<Path fill = "# ff868686" stroke = "# ff868686" strokethickness = "1" Data = "M87, 212l470, 212 470,213 87,213 Z M87, 174l470, 174 470,175 87,175 87,174 Z M87, 135l470, 135 470,136 87,136 Z M87, 97l470, 97 87,135, 98, 98 87, 97z M87, 59l470, 59, 60, 60, 59 "/>
<Canvas name = "barscanvas">
<Canvas. rendertransform>
<Scaletransform X: Name = "barscanvasscale" scaley = "0" centery = "251"/>
</Canvas. rendertransform>
<Canvas. triggers>
<Eventtrigger routedevent = "canvas. Loaded">
<Eventtrigger. Actions>
<Beginstoryboard>
<Storyboard>
<Doubleanimation from = "0" to = "1" Duration = "" storyboard. targetname = "barscanvasscale" storyboard. targetproperty = "scaley"/>
</Storyboard>
</Beginstoryboard>
</Eventtrigger. Actions>
</Eventtrigger>
</Canvas. triggers>
<Polygon name = "bar2003" points = "110,200 110,251 141,251 141,200 110,200" fill = "# ff4f81bd"/>
<Polygon name = "bar2004" points = "187,190 187,251 218,251 218,190 187,190" fill = "# ffc0504d"/>
<Polygon name = "bar2005" points = "263,186 263,251 294,251 294,186 263,186" fill = "# ff9bbb59"/>
<Polygon name = "bar2006" points = "340,162 340,251 371,251 371,162 340,162" fill = "# ff8064a2"/>
<Polygon name = "bar2007" points = "417,251 447,251, 90" fill = "# ff4bacc6"/>
</Canvas>
<Polygon points = "87,250 88,250" fill = "# ff868686" stroke = "# ff868686" strokethickness = "1"/>
<Path fill = "# ff868686" stroke = "# ff868686" strokethickness = "1" Data = "M83, 250l87, 250 87,251 83,251 Z M83, 212l87, 212 87,213 83,213 83,212 Z M83, 174l87, 174 87,175 83,175 83,174 Z M83, 135l87, 135 87,136 83,136 83,135 Z M83, 97l87, 97 87,98 83,98 83, 97z M83, 59l87, 59 87,60 83,60 83,59 "/>
<Polygon points = "87,250 470,250 470,251 87,251" fill = "# ff868686" stroke = "# ff868686" strokethickness = "1"/>
<Path fill = "# ff868686" stroke = "# ff868686" strokethickness = "1" Data = "m88, 250l88, 254 87,254 87,250 Z m165, 250l165, 254 164,254 164,250 165,250 Z m241, 250l241, 254 240,254 240,250 241,250 Z m318, 250l318, 254 317,254 317,250 318,250 Z m394, 250l394, 254 393,254 393,250 394,250 Z m471, 250l471, 254 470,254 470,250 471,250 "/>
<Textblock text = "$0" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "61" canvas. Top = "243"/>
<Textblock text = "$50.000" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "28" canvas. Top = "205"/>
<Textblock text = "$100.000" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "20" canvas. Top = "166"/>
<Textblock text = "$150.000" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "20" canvas. Top = "128"/>
<Textblock text = "$200.000" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "20" canvas. Top = "90"/>
<Textblock text = "$250.000" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "20" canvas. Top = "51"/>
<Textblock text = "2003" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "111" canvas. Top = "263"/>
<Textblock text = "2004" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "188" canvas. Top = "263"/>
<Textblock text = "2005" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "265" canvas. Top = "263"/>
<Textblock text = "2006" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "341" canvas. Top = "263"/>
<Textblock text = "2007" fontfamily = "Arial" fontsize = "13" foreground = "# ff000000" canvas. Left = "418" canvas. Top = "263"/>
<Textblock text = "Net Profit" fontfamily = "Arial" fontweight = "bold" fontsize = "24" foreground = "# ff000000" canvas. left = "191" canvas. top = "15"/>
<Path fill = "# ff868686" stroke = "# ff868686" strokethickness = "1" Data = "f1m5, 5c5, 5, 5, 5, 5l133, 5c133, 5,486, 5,486, 5l133, 293c133, 293,485,294,485,294 L5, 294c5, 294,5, 293,5, 293z M6, 293l5, 293 485,293 485,293, 5, 6, 6 6, 5z "/>
<Textblock name = "valuetextblock" visibility = "Collapsed" text = "$99.999, 00 "fontfamily =" Arial "fontsize =" 13 "fontweight =" bold "foreground =" # ff000000 "/>
<! -- <Grid name = "valuecanvas" visibility = "visible" width = "90" Height = "25">
<Rectangle radiusx = "3" radiusy = "3" fill = "# ddffffc0"/>
<Textblock name = "valuetextblock" text = "$999.999, 00 "verticalignment =" center "horizontalalignment =" center "fontfamily =" Arial "fontsize =" 13 "fontweight =" bold "foreground =" # ff000000 "/>
</GRID> -->
</Canvas>
</GRID>
</Usercontrol>
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Namespace silverlightexcel
{
Public partial class page: usercontrol
{
Private const int start_year = 2003;
Private const int end_year = 2007;
Private polygon _ selectedpolygon;
Private dictionary <int, int> _ yearprofits;
Public page ()
{
Initializecomponent ();
Fillyearprofits ();
Registerbarevents ();
}
Private void fillyearprofits ()
{
_ Yearprofits = new dictionary <int, int> ();
_ Yearprofits. Add (2003,660 00 );
_ Yearprofits. Add (2004,790 00 );
_ Yearprofits. Add (2005,850 00 );
_ Yearprofits. Add (2006,116 000 );
_ Yearprofits. Add (2007,210 000 );
}
Private int getprofitforbar (string barname)
{
Int year;
Int profit;
Try
{
Year = int32.parse (barname. substring (3 ));
Profit = _ yearprofits [year];
}
Catch
{
Profit = 0;
}
Return profit;
}
Private void registerbarevents ()
{
For (INT year = start_year; year <= end_year; year ++)
{
Polygon onebar = This. findname ("bar" + year. tostring () as polygon;
If (onebar! = NULL)
{
Onebar. mouseenter + = new mouseeventhandler (onebar_mouseenter );
Onebar. mouseleave + = new mouseeventhandler (onebar_mouseleave );
}
}
}
Void onebar_mouseenter (Object sender, mouseeventargs E)
{
Polygon currentbar = sender as polygon;
If (currentbar! = NULL)
{
Currentbar. strokethickness = 1;
Currentbar. Stroke = new solidcolorbrush (colors. Black );
_ Selectedpolygon = currentbar;
Valuetextblock. Text = string. Format ("$ {0: #, 000.00 }",
Getprofitforbar (currentbar. Name ));
Valuetextblock. Measure (new size (double. positiveinfinity,
Double. positiveinfinity ));
Rect polygonbounds = getpolygonbounds (currentbar. points );
Valuetextblock. Visibility = visibility. visible;
Canvas. setleft (valuetextblock,
Polygonbounds. x + (polygonbounds. width/2 )-
(Valuetextblock. actualwidth/2 ));
Canvas. settop (valuetextblock, polygonbounds. Y-20 );
}
}
Void onebar_mouseleave (Object sender, mouseeventargs E)
{
If (_ selectedpolygon! = NULL)
{
_ Selectedpolygon. strokethickness = 0;
_ Selectedpolygon. Stroke = NULL;
Valuetextblock. Visibility = visibility. collapsed;
_ Selectedpolygon = NULL;
}
}
Private rect getpolygonbounds (pointcollection points)
{
Double Minx, miny;
Double Maxx, Maxy;
If (points = NULL | points. Count = 0) return rect. empty;
Maxx = 0;
Maxy = 0;
Minx = double. maxvalue;
Miny = double. maxvalue;
Foreach (point onepoint in points)
{
If (onepoint. x <Minx)
Minx = onepoint. X;
If (onepoint. Y <miny)
Miny = onepoint. Y;
If (onepoint. x> Maxx)
Maxx = onepoint. X;
If (onepoint. Y> Maxy)
Maxy = onepoint. Y;
}
Return new rect (Minx, miny, Maxx-Minx, Maxy-miny );
}
}
}