C# (MainWindow.xaml.cs):
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):
<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
沒有留言:
張貼留言