C# (MainWindow.xaml.cs):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using System; using System.Windows; namespace WPFVectorList { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public System.Collections.Generic.List< int > arr = new System.Collections.Generic.List< int >(); private void btn_show_Click( object sender, RoutedEventArgs e) { tbk.Text = "" ; foreach ( int i in arr) { tbk.Text += i + "\n" ; } } private void btn_add_Click( object sender, RoutedEventArgs e) { arr.Add(Int32.Parse(tbx.Text)); } } } |
WPF (MainWindow.xaml):
1 2 3 4 5 6 7 8 9 10 11 | < Window x:Class = "WPFVectorList.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "MainWindow" Height = "350" Width = "525" > < Grid > < TextBlock Margin = "12,12,12,65" Name = "tbk" /> < Button Content = "ADD" Height = "40" HorizontalAlignment = "Left" Margin = "118,259,0,0" Name = "btn_add" VerticalAlignment = "Top" Width = "100" Click = "btn_add_Click" /> < Button Content = "Show" Height = "40" HorizontalAlignment = "Left" Margin = "224,0,0,12" Name = "btn_show" VerticalAlignment = "Bottom" Width = "100" Click = "btn_show_Click" /> < TextBox Height = "40" HorizontalAlignment = "Left" Margin = "12,0,0,12" Name = "tbx" VerticalAlignment = "Bottom" Width = "100" Text = "1" /> </ Grid > </ Window > |
說明:
在C# WPF使用System.Collections.Generic的List實現在陣列Push新值的功能。
MSDN:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
沒有留言:
張貼留言