Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# WPF Introductory Example
04-04-2010, 09:50 AM (This post was last modified: 04-04-2010 09:50 AM by Back_track.)
Post: #1
C# WPF Introductory Example
WPF APPLICATION - EXAMPLE

1) Create the application by - Opening Visual Studio 2008 ( Or Express 2008(C#))
2) Choose WPF Application
3) It should bring you to a screen as such
[Image: 50861_capture.jpg]

The XAML Code should look like:
Code:
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300"></Window>

Now to use the GUI designer click on the tool box
[Image: 50862_capture.jpg]

Add a button to the form, the code should be modified as such:
Code:
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Button Height="23" Margin="94,0,109,12" Name="button1" VerticalAlignment="Bottom">Button</Button>
    </Grid>
</Window>
Now, lets break it down
Code:
<Button Height="23" Margin="94,0,109,12" Name="button1" VerticalAlignment="Bottom">Button</Button>
Code:
<Button Height = "23"
What this is basically saying is the button's height is the value 23
Code:
Margin="94,0,109,12"     // This is giving the margins of the buttons if i'm correct it is each value of the square(Button)
// x,y x,y
Code:
Name="button1"
// Name of the button
Code:
VerticalAlignment="Bottom">Button</Button>
//Vertilical Alignment is Bottom, then the content then the end of it

Now lets change the Buttons 'Content' Text basically
On the XAML Code under the button's code
change the content to Anything
Ill change it to Pro9ramming for now

Now in the tool box add a label , once you added it change the content to null(Blank)
Now, on the button we made double click ,and it should bring you to something you're more familiar with
C# code now type in the following,
Code:
private void button1_Click(object sender, RoutedEventArgs e)
        {
            label1.Content = "P9 Is Rising the Ranks!";
        }

Now you have a basic introduction to WPF programming , i'll be uploading a book or two later
I hope someone gained something off this tutorial, feel free to add your own suggestions and
leave criticisms.

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
04-04-2010, 10:08 AM
Post: #2
RE: C# WPF Introductory Example
Very nice example indeed! I am not a fan of WPF but you have done a great job here!

[Image: pgsig copy.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
04-04-2010, 11:49 AM
Post: #3
RE: C# WPF Introductory Example
Heh, neither am I. It's a weird coding style, but I thought I'd atleast give it a try.

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
04-04-2010, 06:08 PM
Post: #4
RE: C# WPF Introductory Example
Exactly right, it may come in handy some time Wink

[Image: pgsig copy.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
04-04-2010, 09:51 PM
Post: #5
RE: C# WPF Introductory Example
Very good code i can say.
Especially the part with this sentence : "P9 Is Rising the Ranks!"

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: