In Visual Studio:
File -> New -> Project
Installed -> Templates -> Visual C# -> Windows -> WPF Application
Ersetze den Code in MainWindow.xaml durch:
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication2" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525" > <StackPanel> <TextBlock Text="Enter some text"> <TextBox x:Name="ResponseTextBox"> <Button Content="OK" Click="OKButton_Click"> </StackPanel> </Window>
Ersetze den Code in MainWindow.xaml.cs durch:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public string ResponseText { get { return ResponseTextBox.Text; } set { ResponseTextBox.Text = value; } } private void OKButton_Click(object sender, System.Windows.RoutedEventArgs e) { MessageBox.Show("You said: " + ResponseText); } }
Abgeleitet aus: http://stackoverflow.com/a/2796487/1777526
Dann einfach starten und ausprobieren.
Weitere Controls kann man durch drag&drop aus der Toolbox in den XAML-Viewer hinzufügen.