《应用程序=代码+标记》学习中。。
Applications = Code + MarkupPresentation Foundation By Charles Petzold
通过窗体设计器添加两个TextBox,和一个Button,其中textbox1.text为绑定数据用法。
<Window x:Class="HelloWord.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" Loaded="Window_Loaded"> <Grid> <Button Height="23" Margin="105,0,98,50" Name="button1" VerticalAlignment="Bottom" Click="button1_Click">Button</Button> <TextBox Height="23" Margin="84,0,74,89" Name="textBox1" Text="{Binding Path=name }" VerticalAlignment="Bottom" /> <TextBox Height="22" Margin="84,101,74,0" Name="textBox2" VerticalAlignment="Top" MaxLines="1" /> </Grid> </Window>
后台代码:
string name = "aaa"; public Window1() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { this.button1.FontStyle = FontStyles.Italic;//斜体 this.button1.FontWeight = FontWeights.Bold;//粗体 this.textBox1.Text = name;//绑定数据 this.textBox2.Text =Convert.ToString(Math.PI);//得到PI值 }