Posts
74
Comments
75
Trackbacks
0
Visual Studio 2008 Beta 2 - This really is cool!
improve my => 'code'

Wow.... made my first WPF application in seconds flat on Beta 2.

Now when you create a button on the form, you can double click it to make it's event handler, and code right in the contents.  And even more important, the compilations are lightning fast now...

Here's my first application - a Fizz Buzz game (must have beer on the brain).

 

The XAML

<Window x:Class="FizzBuzz.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="FizzBuzz" Height="376" Width="380" Name="FizzBuzz" >

    <Grid Background="BurlyWood" >

        <RichTextBox Margin="64,53,73,123" Name="tOutput" ScrollViewer.VerticalScrollBarVisibility="Auto" />

        <Button Height="23" Margin="145,0,138,66" Name="bPlayFizzBuzz" VerticalAlignment="Bottom" Click="bPlayFizzBuzz_Click">Play Fizz Buzz</Button>

    </Grid>

</Window>

The C#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

 

namespace FizzBuzz

{

    /// <summary>

    /// Interaction logic for Window1.xaml

    /// </summary>

    public partial class Window1 : Window

    {

        private int _FuzzBuzzCounter = 1;

        public int FizzBuzzCounter

        {

            get { return _FuzzBuzzCounter; }

            set { _FuzzBuzzCounter = value; }

        }

 

        private StringBuilder _Response;

 

        /// <summary>

        /// Constructor

        /// </summary>

        public Window1()

        {

            InitializeComponent();

        }

 

        /// <summary>

        /// Handles the button click event for button bPlayFizzBuzz

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void bPlayFizzBuzz_Click(object sender, RoutedEventArgs e)

        {

            _Response = new StringBuilder();

            FizzBuzzEval("fizz", 3, ref _Response);

            FizzBuzzEval("buzz", 5, ref _Response);

            if (_Response.ToString() == String.Empty)

            {

                tOutput.AppendText(FizzBuzzCounter.ToString() + ", ");

            }

            else

            {

                tOutput.AppendText(_Response.ToString() + ", ");

            }

 

            FizzBuzzCounter++;

 

        }

        /// <summary>

        /// Evaluate to Fizz Buzz Rules

        /// </summary>

        /// <param name="positiveResponse"></param>

        /// <param name="numberToEvaluate"></param>

        /// <param name="response"></param>

        private void FizzBuzzEval(string positiveResponse, int numberToEvaluate, ref StringBuilder response)

        {

            if (_FuzzBuzzCounter % numberToEvaluate == 0)

            {

                response.Append(positiveResponse);

            }

        }

    }

}

Happy coding,

Jonathan

 

Tools   Print   Email   Del.icio.us   Digg   reddit
posted on Monday, November 19, 2007 8:56 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 8 and 8 and type the answer here:
News
Jonathan Starr is a developer in Saint Louis, MO. He holds an MBA in Finance from Columbia Business School and earned his MCSD from Microsoft.


All statements in this blog are personal opinions and do not reflect the opinions of his employer.





Related Sites
Join My Community at MyBloglog!

Tag Cloud