WPF and Silverlight Learning notes (vi): WPF forms

Source: Internet
Author: User
Tags xmlns silverlight visual studio

A, Form class

In Visual Studio and Expression Blend, a custom form inherits the System.Windows.Window class (typed form). The defined form consists of two parts:

1. xaml File

1: <Window
2:    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& quot;
3:    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4:   x:Class="WpfWindow.BasicWindow"
5:    x:Name="Window"
6:    Title="BasicWindow"
7:   Width="300"  Height="200">
8:   <Canvas>
9:      <Button x:Name="btnMessage" Width="79"  Height="24" Content="OK"
10:      Canvas.Left="172" Canvas.Top="93"  Click="btnMessage_Click"/>
11:     <TextBox  x:Name="txtValue" Width="215"  Height="25"
12:     Canvas.Left="36"  Canvas.Top="48" Text=""  TextWrapping="Wrap"/>
13:   </Canvas>
14: </Window>

2. Background code file

1:  using System;
2: using System.Windows;
3:
4:  namespace WpfWindow
5: {
6:   public partial class  BasicWindow : Window
7:   {
8:     public  BasicWindow()
9:     {
10:        this.InitializeComponent();
11:     }
12:
13:      private void btnMessage_Click(object sender,  System.Windows.RoutedEventArgs e)
14:     {
15:        txtValue.Text = "Hello World";
16:      }
17:   }
18: }

You can also place the background code in a XAML file, and the example above can be rewritten as:

1: <Window
2:    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& quot;
3:    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4:   x:Class="WpfWindow.BasicWindow"
5:    x:Name="Window"
6:    Title="BasicWindow"
7:   Width="300"  Height="200">
8:   <Canvas>
9:      <Button x:Name="btnMessage" Width="79"  Height="24" Content="OK"
10:      Canvas.Left="172" Canvas.Top="93"  Click="btnMessage_Click"/>
11:      <x:Code><![CDATA[
12:       void  btnMessage_Click(object sender, System.Windows.RoutedEventArgs e)
13:       {
14:         txtValue.Text =  "Hello World";
15:       }
16:      ]]>
17:     </x:Code>
18:      <TextBox x:Name="txtValue" Width="215"  Height="25"
19:     Canvas.Left="36"  Canvas.Top="48" Text=""  TextWrapping="Wrap"/>
20:   </Canvas>
21: </Window>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.