<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Understanding C#</title>
	<atom:link href="http://understandingcsharp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://understandingcsharp.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 03 Mar 2010 03:25:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='understandingcsharp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Understanding C#</title>
		<link>http://understandingcsharp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://understandingcsharp.wordpress.com/osd.xml" title="Understanding C#" />
	<atom:link rel='hub' href='http://understandingcsharp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Moving House</title>
		<link>http://understandingcsharp.wordpress.com/2010/02/23/moving-house/</link>
		<comments>http://understandingcsharp.wordpress.com/2010/02/23/moving-house/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 12:47:29 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[moving]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=171</guid>
		<description><![CDATA[At the time of this post, I am transferring all of the previous posts from this blog over to Blogger. Thus, any old posts and all new posts will be at http://understanding-c-sharp.blogspot.com/ so update your bookmarks.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=171&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>At the time of this post, I am transferring all of the previous posts from this blog over to Blogger.</p>
<p>Thus, any old posts and all new posts will be at <a href="http://understanding-c-sharp.blogspot.com/">http://understanding-c-sharp.blogspot.com/</a> so update your bookmarks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=171&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2010/02/23/moving-house/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Graphing Calculator Demo &#8212; Part 1</title>
		<link>http://understandingcsharp.wordpress.com/2010/02/13/graphing-calculator-demo-part-1/</link>
		<comments>http://understandingcsharp.wordpress.com/2010/02/13/graphing-calculator-demo-part-1/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 07:16:09 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[New Resources]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=167</guid>
		<description><![CDATA[This post has been moved to http://understanding-c-sharp.blogspot.com/2010/02/graphing-calculator-demo-part-1.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=167&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has been moved to <a href="http://understanding-c-sharp.blogspot.com/2010/02/graphing-calculator-demo-part-1.html" title="It’s been nearly a month since my last post but I haven’t been idle. I’ve actually been working hard on a private project and, one day, I may document the steps I took to create it. For now, I’m going to go back to the MSDN samples. This time, I’m not going to bother with a one-to-one port of the program for two reasons: one, it’s a very complicated program; two, I want to focus on the logical elements of the program rather than fiddle with the design aspects.[P][P]The topic here is centered on the Graphing Calculator Demo over at the .NET Framework Library. My goal is to understand the function plotting aspect of the demo. Once I’ve reached that goal then I may extend this series to include the parametric and 3d graphing but that may take a while since I will continue on with my private project before thinking about that.[P][P]First of all, you will notice that someone commented _This sample have [sic.] bugs when opened in Visual Studio 2008. The xaml design window cannot load the file because of errors._ I couldn’t comment back or edit that region in either Chrome or IE so I’ll just write the solution here to kick things off.[P][P]Go to Window1.xaml and follow my fix below:[P][P]    &lt;!--JM: This doesn't work.[P]              &lt;Setter Property=_Background_ Value=_LinearGradient 0,0 0.03,.9 #ffcccccc #ffeeeeee_/&gt;[P]        Check out below for fix.[P]    --&gt;[P]    &lt;Setter Property=_Background_&gt;[P]        &lt;Setter.Value&gt;[P]            &lt;LinearGradientBrush StartPoint=_0,0_ EndPoint=_0.03,.9_&gt;[P]                &lt;GradientStop Color=_#ffcccccc_ Offset=_0_ /&gt;[P]                &lt;GradientStop Color=_#ffeeeeee_ Offset=_1_ /&gt;[P]            &lt;/LinearGradientBrush&gt;[P]        &lt;/Setter.Value&gt;[P]    &lt;/Setter&gt;[P][P]The most interesting part of this program, for me, is the parser so that’s what I will talk about next time.">http://understanding-c-sharp.blogspot.com/2010/02/graphing-calculator-demo-part-1.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=167&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2010/02/13/graphing-calculator-demo-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Concentric Rings Demo &#8212; Part 2</title>
		<link>http://understandingcsharp.wordpress.com/2010/01/15/concentric-rings-demo-part-2/</link>
		<comments>http://understandingcsharp.wordpress.com/2010/01/15/concentric-rings-demo-part-2/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 05:01:11 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[hash code]]></category>
		<category><![CDATA[hashcode]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[New Resources]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[random numbers]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=160</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2010/01/concentric-rings-demo-part-2.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=160&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2010/01/concentric-rings-demo-part-2.html" title="[P][P]Since the window is working nicely, I want to start drawing onto the canvas.[P][P]The final line of the constructor is CreateCircles(); which initializes some parameters for generating the circles then goes into a loop to instantiate and set-up each of the circles.[P][P]Every circle will be centered at (actually, near) the center of the canvas. It is very simple to find the center of the canvas:[P]double centerX = this.MainCanvas.ActualWidth / 2.0;[P]double centerY = this.MainCanvas.ActualHeight / 2.0;[P][P]We don’t know the size of each person’s screen so use the _ActualWidth/ActualHeight_ property to get the rendered dimensions of the canvas width and height respectively. It is possible to set the height and width using the _Width/Height_ property but it may not be rendered with that value for a variety of reasons (here about the height of the object):[P][P]    Height is one of three writable properties on FrameworkElement that specify height information. The other two are MinHeight and MaxHeight. If there is a conflict between these values, the order of application for actual height determination is that first MinHeight must be honored, then MaxHeight, and finally, if it is within bounds, Height.[P][P]The next thing in the _CreateCircles_ method is the list of valid colors for each circle:[P]Color[] colors = new Color[] { Colors.White, Colors.Green, Colors.Green, Colors.Lime };[P][P]Just a simple array of colors, this is good programming practice when you have a specific style in mind or otherwise already know which values should be valid as you then have a specific object with which you can check against to determine if a value is valid or which can be iterated through to retrieve valid values. In this case, we want to choose a color during the for-loop and with this approach we can just choose an arbitrary element from the colors list. To change the aesthetic, it’s simply a matter of reorganizing the list rather than finding and changing all the hard-coded values.[P][P]The colors and center of the canvas are the only values needed to be determined before the loop. Actually, that’s not quite true…many of the values are randomized. The random number object is instantiated in the constructor and the variable for it is declared as an instance variable beforehand:[P]public partial class Window1 : Window[P]{[P]    ...[P]    private Random rand;[P]    public Window1()[P]        {[P]        ...[P]        rand = new Random(this.GetHashCode());[P]                ...[P]        }[P]        ...[P]}[P][P]As noted in the comments of the GetHashCode documentation, it’s not very useful on its own and, I might add, really not useful as a seed for a random number generator. In this case, the object is never different so the seed will always be the same so the random numbers will always have the same sequence. You can see this by running the program more than once–it’s always the same. I would rather seed it with the time the program is run, that way the user will always get something exciting so I used _Environment.TickCount_ instead of _this.GetHashCode()_ for my rewrite.[P][P]When I was looking at the code, I noticed that while the animation looks like each circle is being created at a different time, the loop is instantiating them all at once. I saw each animation was set with a delay and concluded that that’s where the magic happens. To find out if I was right, I commented out all the animation stuff in the for-loop to leave only:[P]Ellipse e = new Ellipse();[P]byte alpha = (byte)rand.Next(96,192);[P]int colorIndex = rand.Next(4);[P]e.Stroke = new SolidColorBrush(Color.FromArgb(alpha, colors[colorIndex].R, colors[colorIndex].G, colors[colorIndex].B));[P]e.StrokeThickness = rand.Next(1, 4);[P]e.Width = 0.0;[P]e.Height = 0.0;[P]double offsetX = 16 - rand.Next(32);[P]double offsetY = 16 - rand.Next(32);[P] [P]this.MainCanvas.Children.Add(e);               [P] [P]e.SetValue(Canvas.LeftProperty, centerX + offsetX);[P]e.SetValue(Canvas.TopProperty, centerY + offsetY);[P][P]Note: Elipses are shapes, they need using System.Windows.Shapes; at the top.[P][P]Of course, without the animation, the circles will not grow so I set _e.Width_ and _e.Height_ to _10.0? for testing purposes. Curiously, those 24 little circles were in the top-left corner of the screen rather than the center. I traced the problem to not inserting this.Show(); before calling the _CreateCircles_ method. What that extra line does is force the window to render along with all its child elements (namely the maximized canvas) that way the layout manager will know where the center is.[P][P]All that’s left to do is animate and since I learned about that (in more detail) from both the Alarm Clock Sample and Calculator Demo, I’m not going to cover it here. I will just note that these animation do not rely on a storyboard, a random delay (offsetXAnimation.BeginTime = TimeSpan.FromSeconds(delay);) is used to make it look like the circles are created at different times, and remember to put using System.Windows.Media.Animation; at the top.[P][P]Also, this works perfectly well without the _DispatcherTimer_ and _lastTick_ variables. I fail to understand their use here. Perhaps I will learn later.">http://understanding-c-sharp.blogspot.com/2010/01/concentric-rings-demo-part-2.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=160&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2010/01/15/concentric-rings-demo-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Concentric Rings Demo &#8212; Part 1</title>
		<link>http://understandingcsharp.wordpress.com/2010/01/13/concentric-rings-demo-part-1/</link>
		<comments>http://understandingcsharp.wordpress.com/2010/01/13/concentric-rings-demo-part-1/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 05:14:39 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[brush]]></category>
		<category><![CDATA[brushes]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[New Resources]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[ResizeMode]]></category>
		<category><![CDATA[WindowState]]></category>
		<category><![CDATA[WindowStyle]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=156</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2010/01/concentric-rings-demo-part-1.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=156&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2010/01/concentric-rings-demo-part-1.html" title="Finally something with more code and less markup…actually, a lot less markup. The only object in markup besides the main application window is a Canvas for drawing the rings. There will be no need to create a method akin to _InitializeComponent_ this time and I will be able to really focus on C# and .NET without worrying about how to translate from XAML.[P][P]Here’s the full translation of the XAML for the window:[P]public class Window1 : Window[P]{[P]    Canvas MainCanvas;[P] [P]    public Window1()[P]    {[P]        //&lt;window ...=&quot;&quot; title=&quot;Concentric Rings&quot; width=&quot;910&quot; height=&quot;512&quot;&gt;[P]        this.Title = &quot;Concentric Rings&quot;;[P]        this.Width = 910;[P]        this.Height = 512;[P] [P]        //&lt;canvas name=&quot;MainCanvas&quot; background=&quot;#FFE0E0E0&quot;&gt;&lt;/canvas&gt;[P]        MainCanvas = new Canvas();[P]        BrushConverter bc = new BrushConverter();[P]        SolidColorBrush brush = bc.ConvertFromString(&quot;#FFE0E0E0&quot;) as SolidColorBrush;[P]        MainCanvas.Background = brush;[P] [P]        this.Content = MainCanvas;[P] [P]    }[P]}[P][P]That’s enough to get the window to show up with a gray canvas. The background was a little tricky. The _Background_ property must be assigned a _Brush_ type so I knew just setting it equal to the string wouldn’t work. I noticed the _BrushConverter_ class thanks to Visual Studio’s autocomplete feature but I wanted to make sure I used it correctly so I searched the internet and found the perfect example. I also made a note to myself that _Canvas_ comes from _System.Windows.Controls_ and _BrushConverter_ (as well as all other brush/color related stuff) comes from _System.Windows.Media_.[P][P]All the rest of the code is already written so all I need to do is come to understand it. I want to finish the container before getting the circles to appear.[P][P]It is very useful to be able to control how the window looks to the user. Sometimes you want them to be able to resize, sometimes you want to remove the border. For the concentric rings, we want the window to be maximized, without any border or titlebar and without showing the taskbar.[P][P]These are the three important lines:[P]this.WindowState = WindowState.Maximized;[P]this.WindowStyle = WindowStyle.None;[P]this.ResizeMode = ResizeMode.NoResize;[P][P]I tried different combinations. Without any of those lines, the window looks like a normal application. By setting _WindowStyle.None_, the titlebar (and buttons) disappear but it still has the border so it can be resized. If you keep the window style normal but set _ResizeMode.NoResize_, you regain the title bar and still have a border but cannot change the size of the window. It is only with both _WindowStyle.None_ and _ResizeMode.NoResize_ does the boarder disappear. That’s nice, but we want it to be maximized. Set _WindowState.Maximized_ and you get a normal looking maximized window. Set _ResizeMode.NoResize_ and magically, the taskbar disappears. What if we say it can be resized but get rid of the title bar? It still forces the taskbar away. So if we want it maximized, why go through the trouble of setting _NoResize_ if it’s not needed to get the look we want? Well, if you _alt-tab_ to another program, you can see the taskbar, then you can right click on _Concentric Rings_ and, if you set _NoResize_, then you won’t be able to restore the window, it will always be maximized. I personally think it would be better to have a windowed and fullscreen mode but perhaps that introduces unnecessary complications…I also think it’s strange the programmer wants to force the window to stay maximized but set the _Width_ and _Height_ properties in XAML.[P][P]Since the window will be maximized at all times with no buttons or other GUI, it would be nice to offer a way to close the application without resorting to the _alt-tab_ trick. For the last part of this part, I’ll look at quitting with the _Escape_ key.[P][P]It’s very simple, especially if you’ve worked with any user interaction before. Just set the event handler for a keypress, check which key, and act appropriately:[P]public Window1()[P]        {[P]                ...[P]                this.KeyDown += new System.Windows.Input.KeyEventHandler(Window1_KeyDown);[P]                ...[P]        }[P] [P]void Window1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)[P]        {[P]                if (e.Key == System.Windows.Input.Key.Escape)[P]                        this.Close();[P]        }[P][P]This is very similar to the Calculator.[P][P]Next time, I will try to understand the use of:[P]System.Windows.Threading.DispatcherTimer frameTimer;[P]private int lastTick;[P]private Random rand;[P][P]We’ve done animation without those objects before, so why use them now?">http://understanding-c-sharp.blogspot.com/2010/01/concentric-rings-demo-part-1.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=156&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2010/01/13/concentric-rings-demo-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculator Demo &#8212; Part 9</title>
		<link>http://understandingcsharp.wordpress.com/2010/01/07/calculator-demo-part-9/</link>
		<comments>http://understandingcsharp.wordpress.com/2010/01/07/calculator-demo-part-9/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 05:18:30 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[dock]]></category>
		<category><![CDATA[dockpanel]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[menuitem]]></category>
		<category><![CDATA[New Resources]]></category>
		<category><![CDATA[submenu]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=152</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2010/01/calculator-demo-part-9.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=152&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2010/01/calculator-demo-part-9.html" title="Getting the memory function to work was very similar to setting up the buttons so I didn’t need to look up anything new. I had never seen menus for .NET yet so I did need to look up a couple things. Overall, however, it was extremely simple and didn’t take much time at all.[P][P]As one would expect, rendering menus is very repetitive. I will only detail the _View_ menu since that required a _checkable_ menu item which makes it more interesting.[P][P]    * Rendering the menu[P]          o XAML:[P]            &lt;menu dockpanel.dock=_Top_ height=_26_&gt;[P]                ...[P]                &lt;menuitem header=_View_&gt;[P]                     &lt;menuitem name=_StandardMenu_ click=_OnMenuStandard_ ischeckable=_true_ ischecked=_True_ header=_Standard_&gt;&lt;/menuitem&gt;[P]                &lt;/menuitem&gt;[P]                ...[P]            &lt;/menu&gt;[P]          o C#:[P]            Menu menu = new Menu();[P]            DockPanel.SetDock(menu, Dock.Top);[P]            menu.Height = 26;[P]            ...[P]            MenuItem view = new MenuItem();[P]            view.Header = _View_;[P]            StandardMenu = new MenuItem();[P]            StandardMenu.Name = _StandardMenu_;[P]            StandardMenu.Click += new RoutedEventHandler(OnMenuStandard);[P]            StandardMenu.IsCheckable = true;[P]            StandardMenu.IsChecked = true;[P]            StandardMenu.Header = _Standard_;[P]            view.Items.Add(StandardMenu);[P]            menu.Items.Add(view);[P]            ...[P]            MyPanel.Children.Add(menu);[P]          o Notes:[P]            The menu bar is set up first and is defined to be docked to the top of the window’s DockPanel. The DockPanel was set up a long time ago to hold the grid. The grid was not docked so I guess DockPanel automatically places other children one after the other if they are not explicitly docked to a certain place. Here, the menu is docked to the top with DockPanel.SetDock(menu, Dock.Top);. I had a little trouble finding that but the .NET Framework Class Library pointed me in the right direction. My other problem was how to add children to the menus because there are a lot of collections and _add_ methods to the _MenuItem_ class. I was told _The submenu of the MenuItem is made up of the objects within the ItemCollection of a MenuItem._ but I had to do some digging to discover _Items.Add(…)_ was the way to go.[P]    * Making it do something[P]          o C#:[P]            void OnMenuStandard(object sender, RoutedEventArgs e)[P]            {[P]                //((MenuItem)ScientificMenu).IsChecked = false;[P]                ((MenuItem)StandardMenu).IsChecked = true; //for now always Standard[P]            }[P]          o Notes:[P]            I didn’t have to change this at all. The original programmer was kind to leave a comment for how this is really supposed to work. There really should be two menu items to mirror windows calculator: one for the standard view and another for the scientific view. To keep things simple, there’s no scientific view so there’s no other menu item. For now, clicking this menu item keeps everything the same but it’s clear how to modify it to add a scientific view, and how to manipulate other menu items.[P][P]I should mention that I declared _StandardMenu_ outside all the methods so that it could be used by both the _InitializeThis_ (for set-up) and _OnMenuStandard_ (for action) methods.[P][P]Both versions now look and act exactly the same way (they both have the same bugs consequently). The Alarm Clock Sample port I wrote ended up having a smaller executable than the original but, for this calculator, the port is larger. That’s interesting to me. I wonder where the difference lies.">http://understanding-c-sharp.blogspot.com/2010/01/calculator-demo-part-9.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=152&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2010/01/07/calculator-demo-part-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculator Demo &#8212; Part 8</title>
		<link>http://understandingcsharp.wordpress.com/2010/01/06/calculator-demo-part-8/</link>
		<comments>http://understandingcsharp.wordpress.com/2010/01/06/calculator-demo-part-8/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 05:52:00 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[textblock]]></category>
		<category><![CDATA[textbox]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=145</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2010/01/calculator-demo-part-8.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=145&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2010/01/calculator-demo-part-8.html" title="[P]The last thing I wanted to do was complete the calculator’s memory. I saved it for last because I thought it would be very simple after finishing everything else. [Unfortunatley, I lied. The memory won't be the last thing to do. I forgot about the menu, but that should be even easier.] I noticed that the original code used a class called _PaperTrail_ which is the last class defined in window1.xaml.cs.[P][P]    * PaperTrail[P]          o C#:[P]            private class PaperTrail[P]                    {[P]                        string args;[P]             [P]                        public PaperTrail()[P]                        {[P]                        }[P]                        public void AddArguments(string a)[P]                        {[P]                            args = a;[P]                        }[P]                        public void AddResult(string r)[P]                        {[P]                            PaperBox.Text += args + _ = _ + r + _\n_;[P]                        }[P]                        public void Clear()[P]                        {[P]                            PaperBox.Text = string.Empty;[P]                            args = string.Empty;[P]                        }[P]                    }[P]          o Notes:[P]            This is a very simple class. The constructor takes no arguments and does nothing. The only three methods are very simple in terms of how complex the code is but they don’t do what I expected them to do. I thought something described as a _paper trail_ would keep a record of the trail but it does no such thing. It calls upon _PaperBox_ to keep the record.[P]    * PaperBox[P]          o C#:[P]            static MyTextBox PaperBox;[P]            ...[P]            PaperBox = new MyTextBox();[P]            Grid.SetRow(PaperBox, 1);[P]            Grid.SetColumn(PaperBox, 0);[P]            Grid.SetColumnSpan(PaperBox, 3);[P]            Grid.SetRowSpan(PaperBox, 5);[P]            PaperBox.IsReadOnly = true;[P]            PaperBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;[P]            PaperBox.Margin = new Thickness(3.0,1.0,1.0,1.0);[P]            PaperBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;[P]          o Notes:[P]            You can find _PaperBox_ defined at the top of the _Window1? class definition. It is simply a textbox like _DisplayBox_ but subclassed differently in the _Window1? constructor to have a different size using the _SetColumnSpan_ and _SetRowSpan_ methods, different interaction by setting the _IsReadOnly_ property to _true_, and a different visual style by making the scroll bars visible, and setting up the margins.[P][P]Now that there’s a place to store memory information, there need to be appropriate buttons to interact with the memory. Microsoft’s programmer decided to have Memory Clear, Memory Save, Memory Recall, and Memory Plus operations. The are found in the _ProcessOperation_ method //Comments by original programmer:[P][P]    * Memory Clear[P]          o C#:[P]            case _BMemClear_:[P]                Memory = 0.0F;[P]                DisplayMemory();[P]                break;[P]          o Notes:[P]            The memory value is stored as a string __mem_val_ accessed through the property _Memory_. Here we want to clear the memory, so the mathematical thing to do is set it to 0 (floating point of course). All of the operations which alter memory call the _DisplayMemory_ method.[P]    * Memory Save[P]          o C#:[P]            case _BMemSave_:[P]                Memory = Convert.ToDouble(Display);[P]                DisplayMemory();[P]                EraseDisplay = true;[P]                break;[P]          o Notes:[P]            Because of EraseDisplay = true;, if you save the display to memory when you are in the middle of an operation, you need to key-in another value (maybe the same one) if you want to perform a binary operation. That is, the number is saved to memory and continues to be displayed but any binary operation will not see it. Unary operations just take the value from the display so they will work as expected.[P]    * Memory Recall[P]          o C#:[P]            case _BMemRecall_:[P]                Display = /*val =*/ Memory.ToString();[P]                UpdateDisplay();[P]                //if (LastOper != Operation.None)   //using MR is like entring a digit[P]                EraseDisplay = false;[P]                break;[P]          o Notes:[P]            Because of _EraseDisplay = false;_, memory recall is like entering a digit. I guess the commented-out partial conditional would have been to make MR act like completing a binary operation with the saved value.[P]    * Memory Plus[P]          o C#:[P]            case _BMemPlus_:[P]                d = Memory + Convert.ToDouble(Display);[P]                Memory = d;[P]                DisplayMemory();[P]                EraseDisplay = true;[P]                break;[P]          o Notes:[P]            The value in the display is added to the value in memory and then saved in memory. Like _BMemSave_, this effectively erases the display so binary operations won’t see it.[P][P]The DisplayMemory method is a bit naughty. It accesses __mem_val_ directly instead of through the _Memory_ property. The author went through pains to start the variable name with an underscore so you would expect him to follow the practice of pretending he can’t access it without the approperiate getter…. Anyway, it also uses a certain object called _BMemBox_ which is defined in XAML so I had to port it to C#:[P][P]    * Memory Display Box[P]          o XAML:[P]            &lt;textblock name=_BMemBox_ grid.column=_3_ grid.row=_1_ margin=_10,17,10,17_ grid.columnspan=_2_&gt;Memory: [empty]&lt;/textblock&gt;[P]          o C#:[P]            BMemBox = new TextBlock();[P]            BMemBox.Name = _BMemBox_;[P]            Grid.SetColumn(BMemBox, 3);[P]            Grid.SetRow(BMemBox, 1);[P]            BMemBox.Margin = new Thickness(10.0, 17.0, 10.0, 17.0);[P]            Grid.SetColumnSpan(BMemBox, 2);[P]            BMemBox.Text = _Memory: [empty]_;[P]            MyGrid.Children.Add(BMemBox);[P]          o Notes:[P]            This is very similar to rendering the buttons but there’s no click event. The styles are all default too.[P][P]I thought this would be the last part to the Calculator Demo series but I forgot about the menu. The next part should be the last part then I will get to choose another program to analyse.">http://understanding-c-sharp.blogspot.com/2010/01/calculator-demo-part-8.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=145&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2010/01/06/calculator-demo-part-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculator Demo &#8212; Part 7</title>
		<link>http://understandingcsharp.wordpress.com/2009/12/31/calculator-demo-part-7/</link>
		<comments>http://understandingcsharp.wordpress.com/2009/12/31/calculator-demo-part-7/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 13:22:01 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[exception handling]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[String.Empty]]></category>
		<category><![CDATA[throw]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=125</guid>
		<description><![CDATA[This post has been moved to http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-7.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=125&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has been moved to <a href="http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-7.html" title="[P]I discovered last time that every operation button invokes the _OperBtn_Click_ event handler on click which calls the _ProcessOperation_ method with the appropriate argument. I want to briefly touch upon each operation in the switch statement of both the _ProcessOperation_ and _Calc_ methods.[P][P]ProcessOperation //Comments by original programmer[P][P]Division[P]C#:[P]case _BDevide_:[P]    if (EraseDisplay)    //stil wait for a digit...[P]    {  //stil wait for a digit...[P]        LastOper = Operation.Devide;[P]        break;[P]    }[P]    CalcResults();[P]    LastOper = Operation.Devide;[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    break;[P]Notes:[P]Many of these are binary operations so if the display has not changed since the last operation that means a second number has not been entered. All of these binary operations wait for a second digit before trying to perform their respective operation or the results wouldn’t make sense. Also of note is that these binary operations overwrite _LastOper_ with themselves so that they will be performed when the next operation is clicked (this means the order of operations for this calculator is strictly left to right).[P]Multiplication[P]C#:[P]case _BMultiply_:[P]    if (EraseDisplay)    //stil wait for a digit...[P]    {  //stil wait for a digit...[P]        LastOper = Operation.Multiply;[P]        break;[P]    }[P]    CalcResults();[P]    LastOper = Operation.Multiply;[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    break;[P]Notes:[P]Another binary operation like above so it follows the same scheme. If a division occurred before this case, _EraseDisplay_ would be true so it would wait for the next digit. If a numerical key was pressed, _EraseDisplay_ would be false so the last operation would be calculated (for example, division) and then _LastOper_ would be set up so that the multiplication happens next (as long as a numerical key is pressed next).[P]Subtraction[P]C#:[P]case _BMinus_:[P]    if (EraseDisplay)    //stil wait for a digit...[P]    {  //stil wait for a digit...[P]        LastOper = Operation.Subtract;[P]        break;[P]    }[P]    CalcResults();[P]    LastOper = Operation.Subtract;[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    break;[P]Notes:[P]If a numerical key is not pressed after the multiplication button–say, the subtraction button is pressed instead–then _LastOper_ will be overridden by the subtraction. In this case, a multiplication would not be performed next, a subtraction would be in the wings.[P]Addition[P]C#:[P]case _BPlus_:[P]    if (EraseDisplay)[P]    {  //stil wait for a digit...[P]        LastOper = Operation.Add;[P]        break;[P]    }[P]    CalcResults();[P]    LastOper = Operation.Add;[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    break;[P]Notes:[P]It’s clear that the _ProcessOperation_ method does not perform the actual operation. This method only sets up the operation for the calculation and asks for the calculation to be performed under the right conditions. One would think, it must be the _CalcResults_ method which must be performing the operation. That’s almost correct. As I investigated previously, _CalcResults_ does one more check[P]Solution[P]C#:[P]case _BEqual_:[P]    if (EraseDisplay)    //stil wait for a digit...[P]        break;[P]    CalcResults();[P]    EraseDisplay = true;[P]    LastOper = Operation.None;[P]    LastValue = Display;[P]    //val = Display;[P]    break;[P]Notes:[P]This isn’t a binary operation so why is it waiting for a second digit? I think they just don’t want _=_ to override any previous operation until there’s actually something to calculate. That last comment is a little puzzling to me as well. I guess there was a variable _val_ used to store the result but it’s not needed since the display is already holding the result so you can always query the display to get the previous result.[P]Take the square root[P]C#:[P]case _BSqrt_:[P]    LastOper = Operation.Sqrt;[P]    LastValue = Display;[P]    CalcResults();[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    LastOper = Operation.None;[P]    break;[P]Notes:[P]Finally, we get an example of a unary operation. It doesn’t need to check if the display is empty, it just operates on whatever is in the display. The display defaults to _0〃 so there’s no problem pushing the square root button immediately after starting the program. All the unary operations set _LastOper_ and _LastValue_ at the start. They set them again after the calculation if needed just like the binary operations.[P]Multiply by a percent[P]C#:[P]case _BPercent_:[P]    if (EraseDisplay)    //stil wait for a digit...[P]    {  //stil wait for a digit...[P]        LastOper = Operation.Percent;[P]        break;[P]    }[P]    CalcResults();[P]    LastOper = Operation.Percent;[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    //LastOper = Operation.None;[P]    break;[P]Notes:[P]I wish percent acted as a unary operation, just dividing your number by 100 and displaying the result. But here, it is used as a binary operation for multiplying one number by another number’s percentage value. You can’t see that from the above except for the hint that given by the conditional that it is a binary operation. I will talk about the _Calc_ method later to revisit how each operation is actually performed in code.[P]Take the reciprocal[P]C#:[P]case _BOneOver_:[P]    LastOper = Operation.OneX;[P]    LastValue = Display;[P]    CalcResults();[P]    LastValue = Display;[P]    EraseDisplay = true;[P]    LastOper = Operation.None;[P]    break;[P]Notes:[P]This is the final mathematical unary operation. It doesn’t look much different from case _BSqrt_ except for the names.[P]Clear all[P]C#:[P]case _BC_:[P]    LastOper = Operation.None;[P]    Display = LastValue = string.Empty;[P]    //Paper.Clear();[P]    UpdateDisplay();[P]    break;[P]Notes:[P]This is one of the operations which doesn’t perform any calculations. It only operates on some variables to, well, clear them. _LastOper_ is cleared with _Operation.None_, _Display_ and _LastValue_ are cleared with _string.Empty_, and _Paper_, which is the history I haven’t yet looked into, is cleared with its _Clear_ method.[P]A couple interesting things about C# is that there is a constant _string.Empty_ supplied out of the box (which actually works differently than the empty string–__–as mentioned in Part 4) and that assignment is carried out right-to-left so Display = LastValue = string.Empty; makes sense and works as expected.[P][P]Clear Entry[P]C#:[P]case _BCE_:[P]    LastOper = Operation.None;[P]    Display = LastValue;[P]    UpdateDisplay();[P]    break;[P]Notes:[P]If you notice you’ve made a mistake before you push _=_, you can undo it by pressing _CE_. This cancels whatever operation you’ve asked the calculator to perform and then sets the display to the last value showing before you keyed in another. Of course, this will only work with binary operations as the unary operations automatically carry out the calculation.[P]Calc [I will ignore any line that references _Paper_][P][P]Division[P]C#:[P]case Operation.Devide:[P]    Paper.AddArguments(LastValue + _ / _ + Display);[P]    d = (Convert.ToDouble(LastValue) / Convert.ToDouble(Display));[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]In order to do math, all values must be numerical types. Recall that _LastValue_ and _Display_ are strings so they have to be converted to a numerical type. In this case, they are converted to doubles which are 64bit floating point numbers. C# doesn’t complain about infinities when dealing with floating point numbers and that makes sense given the IEEE specificiation. The _CheckResult_ method is used to discover values that don’t make sense (for this calculator).[P]Addition[P]C#:[P]case Operation.Add:[P]    Paper.AddArguments(LastValue + _ + _ + Display);[P]    d = Convert.ToDouble(LastValue) + Convert.ToDouble(Display);[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]Recall that _LastValue_ is the value shown in the display before the second operand is entered and _Display_ is what is shown to the user. At this point, _Display_ still holds the value of the second operand. The display will be updated after the final answer, stored in _d_ is returned to the _CalcResults_ method.[P]Multiplication[P]C#:[P]case Operation.Multiply:[P]    Paper.AddArguments(LastValue + _ * _ + Display);[P]    d = Convert.ToDouble(LastValue) * Convert.ToDouble(Display);[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]For all of these operations, you just need to look at the assignment to _d_ for how the operation is performed. Here, we want to multiply so _LastValue_ and _Display_ are converted from strings to doubles and then multiplied with the result stored in _d_.[P]Multiply by a percent[P]C#:[P]case Operation.Percent:[P]    //Note: this is different (but make more sense) then Windows calculator[P]    Paper.AddArguments(LastValue + _ % _ + Display);[P]    d = (Convert.ToDouble(LastValue) * Convert.ToDouble(Display)) / 100.0F;[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]I don’t think this makes more sense than Windows calculator. I would prefer the percent operation to be unary and simply divide the current display by 100 to get ready for whatever operation you want to perform next. When I read 50%, I think of 50/100 = 0.5 and end it. I don’t think of 50 * 1 / 100. And I definitely don’t think of a binary operation.[P]Subtraction[P]C#:[P]case Operation.Subtract:[P]    Paper.AddArguments(LastValue + _ - _ + Display);[P]    d = Convert.ToDouble(LastValue) - Convert.ToDouble(Display);[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]The .NET Framework defines a lot of conversion methods within a variety of classes. I haven’t looked at them all yet. And that doesn’t even include all the different object castings you can perform.[P]Take the square root[P]C#:[P]case Operation.Sqrt:[P]    Paper.AddArguments(_Sqrt( _ + LastValue + _ )_);[P]    d = Math.Sqrt(Convert.ToDouble(LastValue));[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]C# doesn’t include a native Sqrt operation so it is implemented in the Math namespace.[P]Take the reciprocal[P]C#:[P]case Operation.OneX:[P]    Paper.AddArguments(_1 / _ + LastValue);[P]    d = 1.0F / Convert.ToDouble(LastValue);[P]    CheckResult(d);[P]    Paper.AddResult(d.ToString());[P]    break;[P]Notes:[P]This programmer is very OCD about making sure all the numbers are represented as floating points. You don’t need to but it’s good practice to choose one way and stick to it. Here’s a little something I made to test how division in particular is handled:[P]using System;[P] [P]namespace testconsole[P]{[P]    class Program[P]    {[P]        static void Main(string[] args)[P]        {[P]            Console.WriteLine(7 / 2);[P]            Console.WriteLine(7 / 2.0);[P]            Console.WriteLine(7 / 2F);[P]            Console.WriteLine(7 / 2.0F);[P] [P]            Console.WriteLine(7.0 / 2);[P]            Console.WriteLine(7.0 / 2.0);[P]            Console.WriteLine(7.0 / 2F);[P]            Console.WriteLine(7.0 / 2.0F);[P] [P]            Console.WriteLine(7F / 2);[P]            Console.WriteLine(7F / 2.0);[P]            Console.WriteLine(7F / 2F);[P]            Console.WriteLine(7F / 2.0F);[P] [P]            Console.WriteLine(7.0F / 2);[P]            Console.WriteLine(7.0F / 2.0);[P]            Console.WriteLine(7.0F / 2F);[P]            Console.WriteLine(7.0F / 2.0F);[P] [P]            Console.ReadLine();[P]        }[P]    }[P]}[P]Result:[P]3[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P]3.5[P][P]Of course, there are other ways to convert integers to floats but those are the most common shorthands.[P][P]CheckResults:[P][P]Discover invalid numbers[P]C#:[P]private void CheckResult(double d)[P]{[P]    if (Double.IsNegativeInfinity(d) || Double.IsPositiveInfinity(d) || Double.IsNaN(d))[P]        throw new Exception(_Illegal value_);[P]}[P]Notes:[P]There is very useful stuff to remember here. The facts that Double has a method to check for +/- infinity as well as values which are not numbers (NaN) and throwing exceptions. Very handy.[P]All that’s left is displaying the memory and history (paper trail).">http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-7.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=125&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2009/12/31/calculator-demo-part-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculator Demo &#8212; Part 6</title>
		<link>http://understandingcsharp.wordpress.com/2009/12/24/calculator-demo-part-6/</link>
		<comments>http://understandingcsharp.wordpress.com/2009/12/24/calculator-demo-part-6/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 01:44:26 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[catch]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[enumeration]]></category>
		<category><![CDATA[exception handling]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[messagebox]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[try]]></category>
		<category><![CDATA[try/catch]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=114</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-6.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=114&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-6.html" title="[P]For the sake of organization and time, I have completed the animations as promised and I added all the other buttons to the grid. However, I only fully implemented the _+/-_ operation because I thought it best to visit each operation in the next part.[P][P]Rendering the buttons[P]XAML:[P]&lt;Button Name=_BPM_ Click=_OperBtn_Click_ Background=_Darkgray_ Style=_{StaticResource DigitBtn}_  Grid.Column=_6_ Grid.Row=_5_ &gt;+/-&lt;/Button&gt;[P]C#:[P]Button BPM = new Button();[P]BPM.Name = _BPM_;[P]BPM.Click += new RoutedEventHandler(OperBtn_Click);[P]BPM.Background = Brushes.DarkGray;[P]BPM.Style = DigitBtn; //try without resources[P]Grid.SetColumn(BPM, 6);[P]Grid.SetRow(BPM, 5);[P]BPM.Content = _+/-_;[P]MyGrid.Children.Add(BPM);[P]Notes:[P]This is exactly as the buttons I looked at previously except with a different event handler: BPM.Click += new RoutedEventHandler(OperBtn_Click);. Also, when doing some of the other operations there is a tooltip property set (eg. BMemPlus.ToolTip = _Add To Memory_; for the _M+_ button).[P]I wanted the _+/-_ button to work as expected so I followed the Click event:[P][P]OperBtn_Click[P]C#:[P]private void OperBtn_Click(object sender, RoutedEventArgs e)[P]{[P]    ProcessOperation(((Button)sender).Name.ToString());[P]}[P]Notes:[P]All the buttons have their name properties set. In the case of the _+/-_ button we have BPM.Name = _BPM_;. When the above handler is invoked it will then pass the name of the button as an argument to the ProcessOperation method.[P]ProcessOperation[P]C#:[P]private void ProcessOperation(string s)[P]{[P]    Double d = 0.0;[P]    switch (s)[P]    {[P]        case _BPM_:[P]            LastOper = Operation.Negate;[P]            LastValue = Display;[P]            CalcResults();[P]            LastValue = Display;[P]            EraseDisplay = true;[P]            LastOper = Operation.None;[P]            break;[P]        ...[P]    }[P]}[P]Notes:[P]Here we see what happens when calling ProcessOperation(_BPM_);. The variable _d_ is not applicable to this case. First, the most recently clicked operation is saved into _LastOper_ and the most recent value displayed is saved into _LastValue_. By doing this before the calculation, the program is overriding whatever operation was clicked beforehand (that means, if you try to do _2*-2〃 by clicking _2,*,2,+/-_ the multiplication will be forgotten). _LastValue_ and _LastOper_ deserve a closer look later. Next, the calculation is performed by calling _CalcResults_. When the calculation is completed, the current display is again saved however the operation is set to null which is force other operations to not negate again. It is very important to do it this way because this calculator works with infix notation. When I first saw EraseDisplay = true; I thought it meant to actually erase the display but that doesn’t make sense. What it is actually doing is taking a note so that the next operation will know whether it should erase the display (in the case of _ProcessKey_) or whether to simply treat the display as empty (as in several cases of _ProcessOperation_).[P]Operation LastOper[P]C#:[P]private enum Operation[P]{[P]    None,[P]    Devide,[P]    Multiply,[P]    Subtract,[P]    Add,[P]    Percent,[P]    Sqrt,[P]    OneX,[P]    Negate[P]}[P]private Operation LastOper;[P]Notes:[P]I’ve used enums before for setting many properties in but the Alarm Clock Sample and this Calculator Demo but this is the first time I’ve really seen how they are useful. Here, they set us up so it will be very clear which operation is being used and we don’t need to deal with strings. The compiler gives them numbers which is good for computers and we get a descriptive name which is good for us.[P]LastValue[P]C#:[P]private string LastValue[P]{[P]    get[P]    {[P]        if (_last_val == string.Empty)[P]            return _0_;[P]        return _last_val;[P]    }[P]    set[P]    {[P]        _last_val = value;[P]    }[P]}[P]Notes:[P]This is a very simple property declaration but it shows us exactly why getters and setters are useful. This is a calculator application and it’s not very mathematical to show an empty display area so it checks if the last value is an empty string (from _Clear All_) and returns the string _0〃.[P]CalcResults[P]C#:[P]private void CalcResults()[P]{[P]    double d;[P]    if (LastOper == Operation.None)[P]        return;[P] [P]    d = Calc(LastOper);[P]    Display = d.ToString();[P] [P]    UpdateDisplay();[P]}[P]Notes:[P]First, a variable, _d_, is declared to save the numerical result of the upcoming calculation. If there is no operation to be performed (as is the case after _+/-_ is completed), this method just returns and nothing happens. However, if there is an operation to be performed it calls the _Calc_ method to do the dirty work. The result of the operation is sent to the display and the display is updated. Again, I am very aware of object oriented programming at work (I guess it’s actually more of an example of procedural programming since all these functions/methods are in the same class).[P]Calc[P]C#:[P]private double Calc(Operation LastOper)[P]{[P]    double d = 0.0;[P] [P]    try {[P]    switch (LastOper)[P]    {[P]        ...[P]        case Operation.Negate:[P]            d = Convert.ToDouble(LastValue) * (-1.0F);[P]            break;[P]        }[P]    }[P]    catch {[P]        d = 0;[P]        Window parent = (Window)MyPanel.Parent;[P]        //Paper.AddResult(_Error_);[P]        MessageBox.Show(parent, _Operation cannot be perfomed_, parent.Title);[P]    }[P] [P]    return d;[P]}[P]Notes:[P]Again, I am only highlighting _+/-_. The variable _d_ is used store the result of the calculation and then we come to a Try/Catch block for exception handling. Many of the operations check the calculation to make sure there’s nothing strange like infinities and then throw an exception which will be caught by the _catch_ block. I will look at those next time. Notice the Operation.Negate case won’t forcefully throw an exception since it’s only multiplying the last value displayed by negative one and the last value should have already been checked for sanity. However, if something were to go wrong we can see that the error will be noted by adding it to _Paper_ (not relevant now) and a standard message box will be rendered.[P]When you click on a button, a lot of things happen. I think it’s really good that I chose to continue the Calculator Demo. In this part, I got to understand enums, try/except, and a bit more about properties and modular code. I will go through the other operations in the next part though I won’t have to be nearly as detailed as here.[P][P][update Jan 15, 2010][P]I just noticed, I never actually talked about the animation though I did actually complete them at the time.[P][P]I will simply post my code with comments (these go in _InitializeThis_):[P][P]...[P]//&lt;Storyboard x:Key=_playStoryboard_&gt;[P]Storyboard playStoryboard = new Storyboard();[P]this.RegisterName(_playStoryboard_, playStoryboard);[P]//  &lt;DoubleAnimation From=_50_  To=_40_ Duration=_0:0:0.25_ RepeatBehavior=_1x_ AutoReverse=_True_[P]//      Storyboard.TargetName=_TB_ Storyboard.TargetProperty=_(Ellipse.Height)_/&gt;[P]DoubleAnimation TBHeightAnimation = new DoubleAnimation(50.0, 40.0, new Duration(new TimeSpan(0, 0, 0, 0, 250))); //guess[P]TBHeightAnimation.RepeatBehavior = new RepeatBehavior(1.0); //1x gives the error _cannot implicitly convert int to RepeatBehaviour_[P]TBHeightAnimation.AutoReverse = true;[P]Storyboard.SetTargetName(TBHeightAnimation, _TB_);[P]Storyboard.SetTargetProperty(TBHeightAnimation, new PropertyPath(Ellipse.HeightProperty));[P]playStoryboard.Children.Add(TBHeightAnimation);[P] [P]//  &lt;DoubleAnimation From=_50_  To=_44_ Duration=_0:0:0.25_ RepeatBehavior=_1x_ AutoReverse=_True_[P]//      Storyboard.TargetName=_TB_ Storyboard.TargetProperty=_(Ellipse.Width)_/&gt;[P]DoubleAnimation TBWidthAnimation = new DoubleAnimation(50.0, 44.0, new Duration(new TimeSpan(0, 0, 0, 0, 250)));[P]TBWidthAnimation.RepeatBehavior = new RepeatBehavior(1.0);[P]TBWidthAnimation.AutoReverse = true;[P]Storyboard.SetTargetName(TBWidthAnimation, _TB_);[P]Storyboard.SetTargetProperty(TBWidthAnimation, new PropertyPath(Ellipse.WidthProperty));[P]playStoryboard.Children.Add(TBWidthAnimation);[P]//&lt;/Storyboard&gt;[P]MyGrid.Resources.Add(_playStoryboard_, playStoryboard);[P]/* The animations make the ellipses become circles... (including Microsoft's) */[P]...[P]Near the definition of setter4[P][P]this.RegisterName(_TB_, TB);[P]...[P]//&lt;ControlTemplate.Triggers&gt;[P]//    &lt;Trigger Property=_IsMouseOver_ Value=_true_&gt;[P]Trigger IMO = new Trigger();[P]IMO.Property = Button.IsMouseOverProperty; //guess[P]IMO.Value = true;[P]//        &lt;Setter TargetName=_TB_ Property=_Ellipse.Fill_ Value=_Lightblue_ /&gt;[P]Setter IMOSetter = new Setter(Ellipse.FillProperty, Brushes.LightBlue, _TB_);[P]IMO.Setters.Add(IMOSetter);[P]//    &lt;/Trigger&gt;[P]ct.Triggers.Add(IMO);[P] [P]//    &lt;Trigger Property=_IsPressed_ Value=_true_&gt;[P]Trigger IP = new Trigger();[P]IP.Property = Button.IsPressedProperty;[P]IP.Value = true;[P]//        &lt;Setter TargetName=_TB_ Property=_Ellipse.Fill_ Value=_Blue_ /&gt;[P]Setter IPSetter = new Setter(Ellipse.FillProperty, Brushes.Blue, _TB_);[P]IP.Setters.Add(IPSetter);[P]//    &lt;/Trigger&gt;[P]ct.Triggers.Add(IP);[P] [P]//    &lt;EventTrigger RoutedEvent=_ButtonBase.Click_&gt;[P]//http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.aspx[P]EventTrigger BBC = new EventTrigger(System.Windows.Controls.Primitives.ButtonBase.ClickEvent);[P]//        &lt;EventTrigger.Actions&gt;[P]//            &lt;BeginStoryboard Name=_playStoryboard_ Storyboard=_{StaticResource playStoryboard}_/&gt;[P]BeginStoryboard BsPs = new BeginStoryboard();[P]BsPs.Storyboard = (Storyboard)MyGrid.Resources[_playStoryboard_];[P]BsPs.Name = _playStoryboard_;[P]//        &lt;/EventTrigger.Actions&gt;[P]BBC.Actions.Add(BsPs);[P]//    &lt;/EventTrigger&gt;[P]ct.Triggers.Add(BBC);[P]//&lt;/ControlTemplate.Triggers&gt;[P][/update]">http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-6.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=114&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2009/12/24/calculator-demo-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculator Demo &#8212; Part 5</title>
		<link>http://understandingcsharp.wordpress.com/2009/12/20/calculator-demo-part-5/</link>
		<comments>http://understandingcsharp.wordpress.com/2009/12/20/calculator-demo-part-5/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 08:46:20 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[content presenter]]></category>
		<category><![CDATA[fontsize]]></category>
		<category><![CDATA[frameworkelementfactory]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[margin]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[New Resources]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[relativesource]]></category>
		<category><![CDATA[setter]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[templatedparent]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=96</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2009/12/it-took-so-much-effort-to-style-buttons.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=96&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2009/12/it-took-so-much-effort-to-style-buttons.html" title="[p]It took so much effort to style the buttons that I’m not going to do the animations until next time. Instead of playing around with the animations like I said I would, I just made sure pressing the buttons would put the respective value into the display area.[p][p]I had to do a lot of research to translate the XAML for this part into C# so I will follow the same structure that I tried in Alarm Clock Sample — Part 6 (this time using the sourcecode shortcode).[p][p]Defining the button style[p]XAML:[p]&lt;Style x:Key=_DigitBtn_  TargetType=_{x:Type Button}_&gt;[p]C#:[p]Style DigitBtn = new Style();[p]DigitBtn.TargetType = typeof(Button);[p]Notes:[p]I simply looked up the x:Type Markup Extension and followed my nose after reading _x:Type is essentially a markup extension equivalent for a typeof() operator in C#_. Basically, this is telling the complier that the program will only be applying this style to Button objects.[p]Setting the _Focusable_ property[p]XAML:[p]&lt;Setter Property=_Focusable_ Value=_False_/&gt;[p]C#:[p]Setter setter1 = new Setter(Button.FocusableProperty, false);[p]DigitBtn.Setters.Add(setter1);[p]Notes:[p]Since this is the first _Setter_ I’ve seen, I needed to look up the constructor. However, I still didn’t understand what all this was for until I read WPF Data Binding – DataTriggers though I only cared about the Data Binding part. It seems that because we are targeting buttons, we can set any properties that buttons have. This really makes me think of CSS classes because this program is going to have a bunch of buttons all with the same style so it makes sense to set up the style first and then, when you create the button element, you specify which style to use (similar to &lt;input type=_button_ value=_Submit_ class=_DigitBtn_&gt; for HTML+CSS).[p]Setting the _FontSize_ property[p]XAML:[p]&lt;Setter Property=_FontSize_ Value=_14pt_/&gt;[p]C#:[p]LengthConverter lc = new LengthConverter();[p]string qualifiedDouble = _14pt_;[p]Setter setter2 = new Setter(Button.FontSizeProperty, lc.ConvertFrom(qualifiedDouble));[p]DigitBtn.Setters.Add(setter2);[p]Notes:[p]Wow, so much work for something so simple. I would have never guessed this on my own…I know, I tried for quite a while. Thankfully, someone from the internets had the answer (and a pretty good explanation).[p]Setting the _Margin_ property[p]XAML:[p]&lt;Setter Property=_Margin_ Value=_0_/&gt;[p]C#:[p]Setter setter3 = new Setter(Button.MarginProperty, new Thickness(0));[p]DigitBtn.Setters.Add(setter3);[p]Notes:[p]Who would have guessed margins take values of Thickness Structures? It makes sense now that I look closer. Instead of specifying that something has a left, top, bottom, and right margin you just say it has a margin and you define a margin to be something that has left, top, bottom, and right properties.[p]The final property _Template_ is much more involved so I will describe what I did from the inside-out. Of course, I didn’t deal with any animations or other triggers. I just wanted the buttons to show up and work.[p][p]Presenting the button’s content[p]XAML:[p]&lt;ContentPresenter Content=_{TemplateBinding Content}_ HorizontalAlignment=_Center_ VerticalAlignment=_Center_/&gt;[p]C#:[p]FrameworkElementFactory CP = new FrameworkElementFactory(typeof(ContentPresenter));[p]Binding TBinding = new Binding(_Content_){RelativeSource = RelativeSource.TemplatedParent, Mode = BindingMode.OneWay};[p]CP.SetValue(ContentPresenter.ContentProperty, TBinding);[p]CP.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);[p]CP.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);[p]Notes:[p]All of this gets nested inside a ControlTemplate which was giving me a lot of problems because it doesn’t work the same way as other containers (in C#–they all look the same in XAML). Fortunately, a quick Google search came up with Changing the drawing style of a button from code which introduced me to FrameworkElementFactory. I had to read two more sources of information to figure out Content=_{TemplateBinding Content}_: one, TemplateBinding Markup Extension, told me that _A TemplateBinding is an optimized form of a Binding for template scenarios, analogous to a Binding constructed with {Binding RelativeSource={RelativeSource TemplatedParent} Mode=OneWay}._; two, How to: Create a Binding in Code, had an extremely useful comment by LukeSkywalker (of all people). I tried running the code without the ContentPresenter and, lo and behold, the button’s content, which holds the text, didn’t show.[p]Styling the Button[p]XAML:[p]&lt;Ellipse Width=_57_ Height=_49_ x:Name=_TB_  StrokeThickness=_1_ Stroke=_{TemplateBinding Foreground}_ Fill=_{TemplateBinding Background}_ HorizontalAlignment=_Center_ VerticalAlignment=_Center_ /&gt;[p]C#:[p]FrameworkElementFactory TB = new FrameworkElementFactory(typeof(Ellipse), _TB_);[p]TB.SetValue(Ellipse.WidthProperty, 57.0);[p]TB.SetValue(Ellipse.HeightProperty, 49.0);[p]TB.SetValue(Ellipse.StrokeThicknessProperty, 1.0);[p]TB.SetValue(Ellipse.StrokeProperty, new Binding(_Foreground_) { RelativeSource = RelativeSource.TemplatedParent, Mode = BindingMode.OneWay });[p]TB.SetValue(Ellipse.FillProperty, new Binding(_Background_) { RelativeSource = RelativeSource.TemplatedParent, Mode = BindingMode.OneWay });[p]TB.SetValue(Ellipse.HorizontalAlignmentProperty, HorizontalAlignment.Center);[p]TB.SetValue(Ellipse.VerticalAlignmentProperty, VerticalAlignment.Center);[p]Notes:[p]I quickly discovered, thanks to the compiler, that Height, Width and StrokeThickness need to have values of type Double so I simply added the decimal point to squash those errors. As for the bindings, this time I went for in-line declarations. I think that looks more organized.[p]Completing the Template setter[p]XAML:[p]&lt;Setter Property=_Template_&gt;[p]    &lt;Setter.Value&gt;[p]        &lt;ControlTemplate TargetType=_{x:Type Button}_&gt;[p]            &lt;Grid Width=_60_ Height=_50_&gt;[p]                ...[p]            &lt;/Grid&gt;[p]        &lt;/ControlTemplate&gt;[p]    &lt;/Setter.Value&gt;[p]&lt;/Setter&gt;[p]C#:[p]Setter setter4 = new Setter();[p]setter4.Property = Button.TemplateProperty;[p] [p]ControlTemplate ct = new ControlTemplate(typeof(Button));[p] [p]FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid));[p]grid.SetValue(Grid.WidthProperty, 60.0);[p]grid.SetValue(Grid.HeightProperty, 50.0);[p] [p]...[p] [p]grid.AppendChild(TB);[p]grid.AppendChild(CP);[p] [p]ct.VisualTree = grid;[p] [p]setter4.Value = ct;[p]DigitBtn.Setters.Add(setter4);[p]Notes:[p]Because I was going to have to separate this setter’s Value property, I used the empty constructor and then acted on the instance. Setting the setter’s property property (that was fun to write) was as straight forward as the others. To set the setter’s value property, I first created a ControlTemplate targeting a Button. Then I created a grid to hold the Ellipse and ContentPresenter. After instantiating the object to go into the grid, I discovered that I couldn’t treat this grid object like I have before because it’s actually a FrameworkElementFactory object. It was easy to find out how to add children to it though. Finally, thanks to Douglass Stockwell, I knew how to use VisualTree to complete the setter.[p]Adding the style to the main grid[p]XAML:[p]&lt;Grid.Resources &gt;[p]    ...[p]    &lt;/Style&gt;[p]&lt;/Grid.Resources&gt;[p]C#:[p]MyGrid.Resources.Add(_DigitBtn_, DigitBtn);[p]Notes:[p]The style is defined inside the _Grid.Resources_ tag so I added the style to MyGrid.Resources collection in the same way as adding the storyboard to the Window.Resources collection of the Alarm Clock Sample.[p]Now that I got the style set up, I moved on to rendering the buttons. This part is just copy/paste once you get the first button to show. (In fact, I think it’s so copy/paste that I might rewrite it using a loop.)[p][p]It was a little tricky for me because I haven’t dealt with this level of customized UI before (at least with C#. I have done a complex GUI in Python with TkInter but TkInter’s grid and pack managers are much less sophisticated).[p][p]Initializing the grid[p]XAML:[p]&lt;Grid.ColumnDefinitions&gt;[p]  &lt;ColumnDefinition/&gt;[p]  ...[p]  &lt;ColumnDefinition/&gt;[p]&lt;/Grid.ColumnDefinitions&gt;[p]&lt;Grid.RowDefinitions&gt;[p]  &lt;RowDefinition/&gt;[p]  ...[p]  &lt;RowDefinition/&gt;[p]&lt;/Grid.RowDefinitions&gt;[p]C#:[p]MyGrid.ColumnDefinitions.Add(new ColumnDefinition());[p]...[p]MyGrid.RowDefinitions.Add(new RowDefinition());[p]Notes:[p]I tried rendering a button without this and it just overlapped with the DisplayBox. The grid geometry manager in TkInter automatically creates the cells and I assumed WPF grids worked the same. I saw all this XAML which did nothing but create default objects and thought, the code doesn’t need this, but I was wrong. You explicitly have to create the rows and columns first, otherwise every visual object will overlap even if you’ve told the grid to put it somewhere else.[p]Creating the buttons[p]XAML:[p]&lt;Button Name=_B7_ Click=_DigitBtn_Click_ Style=_{StaticResource DigitBtn}_ Grid.Column=_4_ Grid.Row=_2_&gt;7&lt;/Button&gt;[p]...[p]C#:[p]Button B7 = new Button();[p]B7.Name = _B7_;[p]B7.Click += new RoutedEventHandler(DigitBtn_Click);[p]B7.Style = MyGrid.Resources[_DigitBtn_] as Style;[p]Grid.SetColumn(B7, 4);[p]Grid.SetRow(B7, 2);[p]B7.Content = _7_;[p]MyGrid.Children.Add(B7);[p]Notes:[p]It all made sense until the little _7〃 stuck between the tags. I looked up how to get the text for a button to show up and that led me to the wrong Button Class. It was telling me to set the Button.Text property but the compiler told me it doesn’t exist. Someone else said, _WPF C# .text not working_ and later said they were being an idiot because one should set the Button.Content property. I went back to the .NET Framework Class Library and discovered that I, too, was being an idiot because the correct place to look is the System.Windows.Controls.Button Class which does, indeed, have a Button.Content property. Oh, and also note _as Style_ when grabbing the Style resource. In the Alarm Clock Sample, the storyboard resource is grabbed with a cast (Storyboard)clockWindow.Resources[_clockHandStoryboard_]. The big difference between using a cast and using _as_ is a cast will raise an exception but _as_ will just yield null.[p]I then copied the DigitBtn_Click method into my Window1 class and now my unfinished calculator is at least looking much more finished. (I still don’t know why they are converting the string into a character array instead of indexing the string itself…)[p][p]I planned on animating the buttons in this installment but just getting the buttons to render correctly was enough work for this time. I promise to do the animations next. I may even add in the operations.">http://understanding-c-sharp.blogspot.com/2009/12/it-took-so-much-effort-to-style-buttons.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=96&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2009/12/20/calculator-demo-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculator Demo &#8212; Part 4</title>
		<link>http://understandingcsharp.wordpress.com/2009/12/14/calculator-demo-part-4/</link>
		<comments>http://understandingcsharp.wordpress.com/2009/12/14/calculator-demo-part-4/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 11:01:25 +0000</pubDate>
		<dc:creator>jmancine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[New Resources]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[String.Empty]]></category>
		<category><![CDATA[textbox]]></category>
		<category><![CDATA[TkInter]]></category>

		<guid isPermaLink="false">http://understandingcsharp.wordpress.com/?p=91</guid>
		<description><![CDATA[This post has moved to http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-4.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=91&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has moved to <a href="http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-4.html" title="[P]After getting the window working, I wanted some interaction. I looked at _ProcessKey()_ to get started. I simply uncommented it in the _OnWindowKeyDown_ method and then followed the code until there were no build errors.[P][P]It’s a very simple method as OOP recommends (I put in my own comments):[P][P]private void ProcessKey(char c)[P]{[P]  if (EraseDisplay) //EraseDisplay is a property[P]  {[P]    Display = string.Empty; //Display is a property[P]    EraseDisplay = false;[P]  }[P]  AddToDisplay(c);[P]}[P][P]This method first checks if we want to erase the display. (As commented, EraseDisplay and Display are properties of this class which I will look at next.) It then clears the Display property if need be and then calls a method to add the newly pressed character to the display.[P][P]Properties are a really cool feature of C#. This tutorial by C# Station is a great introduction to how they can be used. Basically, they take away all the hassle of using getter/setter methods while still allowing you to customize how getting/setting is performed. The EraseDisplay and Display properties are as simple as you can get — and they could easily be removed to use the naked variables __erasediplay_ [sic] and __display_ — but, by structuring the code so that those variables be handled through properties allows for expansion such as validation or calling subroutines, etc.[P][P]Lastly, _AddToDisplay_ is called. I think the programmer for this one wanted to make an example of nesting conditionals because it seems unnecessary (and I would have done it differently). Anyway, it starts by checking if a decimal point is already displayed. I’ve seen something like _IndexOf_ in Python. It simply returns the index of the position in the string of the character you’re looking for. String indexes start at 0 so if it returns a number greater than or equal to 0 then it does appear in the string and the method returns without changing the display (what number system uses more than one decimal point?) otherwise, it inserts the decimal point at the end. If the user presses a number the next conditional gets invoked which simply inserts the number at the end. If the user presses backspace, the final conditional is invoked which removes a single character from the end or sets the display to empty if there are no more characters to remove. Finally, and in any situation except the forced return, there is a call to _UpdateDisplay_.[P][P]I’m definitely getting a better understanding of OOP principles. Each method above is focused on a single task and, if it needs to do something tangential to its core function, it calls upon another method to do that job. _ProcessKey_ only exists to get the display ready before sending the character onto _AddToDisplay_ which which does the work of altering the state of the display before calling _UpdateDisplay_ which actually renders the new state.[P][P]The _UpdateDisplay_ method warrants a closer look because it is so simple yet does so much (and there’s a lot of interesting stuff to talk about):[P][P]private void UpdateDisplay()[P]{[P]  if (Display == String.Empty) //String.Empty vs Display.Length == 0[P]    DisplayBox.Text = _0_; //DisplayBox is of type MyTextBox initialized in the constructor[P]  else[P]    DisplayBox.Text = Display;[P]}[P][P]I say this method is simple because all it does is check if the display is empty and sets the text of _DisplayBox_ (what the user sees) to 0 or to whatever value is in Display. I say it does so much because it makes use of a conditional, an interesting compare, and introduces a GUI element that it must alter.[P][P]Back when I was working on the Alarm Clock Sample, I came across a website that compared String.Empty with Foo.Length tests. I found another article which explains why the length test would work so much faster. I would like someone to explain why it is ever useful because I intend to never use it in my own code from now on.[P][P]Now for the GUI. I first noticed _DisplayBox_ is an instance of the class _MyTextBox_ which is defined in the file mytextbox.cs. It inherits from _System.Windows.Controls.TextBox_ and only overrides the _OnPreviewGotKeyboardFocus_ event handler method and is being used exactly as recommended: mark it as handled and then invoke the base class implementation to keep the train rolling. Second, I saw that the _DisplayBox_ instance is added to the layout by use of the Grid. The grid is setup with XAML so I stuck it in my _InitializeThis_ method:[P][P]//&lt;DockPanel Name=_MyPanel_&gt;[P]MyPanel = new DockPanel();[P][P]//[P]MyGrid = new Grid();[P]MyGrid.Name = _MyGrid_;[P]MyGrid.Background = Brushes.Wheat;[P]MyGrid.ShowGridLines = false;[P][P]//[P]MyPanel.Children.Add(MyGrid);[P][P]//[P]this.Content = MyPanel;[P][P]I declared each instance variable outside the methods and marked them as _static_ because they are logically contained within the entire and every _window1〃 object. The rest of the code is a direct translation from XAML based on what I came to understand previously so I won’t explain it further. However, I will explain my understanding of how _Grid_ works. Again, I have to thank my Python experience for this. We tell the _DockPanel_ that a Grid will manage the position and geometry of specified GUI objects (widgets). The Grid in .NET is much more sophisticated than TkInter in that you can specify many aspects of the Grid’s display rather than simply indicate how it will manage geometry, and, you must specify which objects will be managed by the Grid. The content of the window is then set as the _DockPanel_ so it knows what to render for viewing.[P][P]I will implement the button animations next to flesh out the GUI, play around with animations again, and get ready for implementing operations.">http://understanding-c-sharp.blogspot.com/2009/12/calculator-demo-part-4.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/understandingcsharp.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/understandingcsharp.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/understandingcsharp.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/understandingcsharp.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/understandingcsharp.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/understandingcsharp.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/understandingcsharp.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/understandingcsharp.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=understandingcsharp.wordpress.com&amp;blog=10712890&amp;post=91&amp;subd=understandingcsharp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://understandingcsharp.wordpress.com/2009/12/14/calculator-demo-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/07b6d876df99f4d8cefcee44f08720a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jmancine</media:title>
		</media:content>
	</item>
	</channel>
</rss>
