Geeks With Blogs
Jonathan Starr's Blog Thoughts on C#, Ajax, WCF, LINQ, Agile et al.
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 C# , Software Design | Back to top


Comments on this post: Visual Studio 2008 Beta 2 - This really is cool!

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jonathan Starr | Powered by: GeeksWithBlogs.net