WPF mit C# [] (WPF mit C#), Lektion, Seite 723345
https://www.purl.org/stefan_ram/pub/wpf_csharp (Permalink) ist die kanonische URI dieser Seite.
Stefan Ram
C#-Kurs

WPF  mit C♯ 

Vorbereitung

Für die WPF -Programmierung müssen einige zusätzliche Bibliotheken referenziert werden.

Program64.cmd
if exist C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe set CSC=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe 

if exist C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe set CSC=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe 

"%CSC%" /reference:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.JScript.dll ^
/reference:System.IO.Compression.FileSystem.dll ^
/reference:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\PresentationCore.dll ^
/reference:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\PresentationFramework.dll ^
/reference:System.dll ^
/reference:System.Windows.dll ^
/reference:System.Xaml.dll ^
/reference:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\WindowsBase.dll ^
Program.cs Program.exe PAUSE
Program32.cmd
if exist C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe set CSC=C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe 

if exist C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe set CSC=C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe 

"%CSC%" /reference:C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.JScript.dll ^
/reference:System.IO.Compression.FileSystem.dll ^
/reference:C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationCore.dll ^
/reference:C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationFramework.dll ^
/reference:System.dll ^
/reference:System.Windows.dll ^
/reference:System.Xaml.dll ^
/reference:C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\WindowsBase.dll ^
Program.cs Program.exe PAUSE

»[global::System.STAThread]«

Das Attribut »[global::System.STAThread]« muß der Hauptmethode von Programmen, die WPF  verwenden, gegeben werden. Es ist zur WPF -Programmierung nicht nötig, die genaue Bedeutung dieses Attributes zu kennen.

Program.cs
public static class Program
{ [global::System.STAThread] public static void Main()
{ }}

»System.Windows.Application«

Die Klasse des Programmes muß die Klasse »System.Windows.Application« erweitern. Dazu darf sie nicht mehr »static« sein.

Program.cs
public class Program : global::System.Windows.Application
{ [global::System.STAThread] public static void Main()
{ }}

»System.Windows.Window«

Das folgende Programm zeigt ein neues Fenster an. Da das Programm aber unmittelbar danach endet, wird das Fenster auch sofort wieder geschlossen.

Program.cs
public class Program : global::System.Windows.Application
{ [global::System.STAThread] public static void Main()
{ global::System.Windows.Window window = new System.Windows.Window();
window.Show();
}}

»new global::System.Windows.Application().Run()«

Durch den Aufruf der Run-Methode wird ein Ereigniswächter gestartet, der auf eventuelle Eingaben in dem Fenster reagieren kann. Solange dieser läuft bleibt auch das Fenster sichtbar.

Program.cs
public class Program : global::System.Windows.Application
{ [global::System.STAThread] public static void Main()
{ global::System.Windows.Window window = new System.Windows.Window();
window.Show();
new global::System.Windows.Application().Run(); }}
Program.cs
public class Program : global::System.Windows.Application
{ [global::System.STAThread] public static void Main()
{ global::System.Windows.Window window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
window.Show();
new global::System.Windows.Application().Run(); }}
Program.cs
public class Program : global::System.Windows.Application
{ [global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
var textBox = new global::System.Windows.Controls.TextBox();
window.Content = textBox;
window.Show();
new global::System.Windows.Application().Run(); }}
Program.cs
public class Program : global::System.Windows.Application
{ static readonly global::System.Windows.Controls.TextBox textBox
= new global::System.Windows.Controls.TextBox();
[global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
textBox.FontSize *= 4;
textBox.TextInput += /* Strg-Eingabe */
new global::System.Windows.Input.TextCompositionEventHandler( TextInput );
window.Content = textBox;
window.Show();
new global::System.Windows.Application().Run(); }
static void TextInput
( global::System.Object @object, global::System.EventArgs args )
{ global::System.Console.WriteLine( textBox.Text ); }}
Program.cs
public class Program : global::System.Windows.Application
{ static readonly global::System.Windows.Controls.TextBox textBox
= new global::System.Windows.Controls.TextBox();
[global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
textBox.FontSize *= 4;
textBox.TextInput += /* Strg-Eingabe */
new global::System.Windows.Input.TextCompositionEventHandler( TextInput );
window.Content = textBox;
window.Show();
new global::System.Windows.Application().Run(); }
static void TextInput
( global::System.Object @object, global::System.EventArgs args )
{ textBox.Text = "abc"; }}
Program.cs
public class Program : global::System.Windows.Application
{ static readonly global::System.Windows.Controls.TextBox textBox
= new global::System.Windows.Controls.TextBox();
[global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
textBox.FontSize *= 4;
textBox.TextInput += /* Strg-Eingabe */
new global::System.Windows.Input.TextCompositionEventHandler( TextInput );
window.Content = textBox;
window.Show();
new global::System.Windows.Application().Run(); }
static void TextInput
( global::System.Object @object, global::System.EventArgs args )
{ textBox.Text = textBox.Text.ToUpper(); }}
Program.cs
public class Program : global::System.Windows.Application
{ static readonly global::System.Windows.Controls.TextBox textBox
= new global::System.Windows.Controls.TextBox();
static readonly global::System.Windows.Controls.TextBox textBox1
= new global::System.Windows.Controls.TextBox();
[global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
textBox.FontSize *= 4;
textBox1.FontSize *= 4;
textBox.TextInput += /* Strg-Eingabe */
new global::System.Windows.Input.TextCompositionEventHandler( TextInput );
var stackPanel
= new global::System.Windows.Controls.StackPanel();
stackPanel.Orientation = global::System.Windows.Controls.Orientation.Vertical;
stackPanel.Children.Add( textBox );
stackPanel.Children.Add( textBox1 );
window.Content = stackPanel;
window.Show();
new global::System.Windows.Application().Run(); }
static void TextInput
( global::System.Object @object, global::System.EventArgs args )
{ textBox1.Text = textBox.Text.ToUpper(); }}
Program.cs
public class Program : global::System.Windows.Application
{ static readonly global::System.Windows.Controls.TextBox textBox
= new global::System.Windows.Controls.TextBox();
static readonly global::System.Windows.Controls.TextBox textBox1
= new global::System.Windows.Controls.TextBox();
[global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
textBox.FontSize *= 4;
textBox1.FontSize *= 4;
textBox.TextInput += /* Strg-Eingabe */
new global::System.Windows.Input.TextCompositionEventHandler( TextInput );
var stackPanel
= new global::System.Windows.Controls.StackPanel();
stackPanel.Orientation = global::System.Windows.Controls.Orientation.Vertical;
stackPanel.Children.Add( textBox );
stackPanel.Children.Add( textBox1 );
window.Content = stackPanel;
window.Show();
new global::System.Windows.Application().Run(); }
static void TextInput
( global::System.Object @object, global::System.EventArgs args )
{ textBox1.Text =
global::System.Convert.ToString
( global::System.Convert.ToInt32
(
textBox.Text )* 2 ); }}
Program.cs
public class Program : global::System.Windows.Application
{ private static readonly global::System.Windows.Controls.TextBox textBox
= new global::System.Windows.Controls.TextBox();
private static readonly global::System.Windows.Controls.TextBox textBox1
= new global::System.Windows.Controls.TextBox();
private static readonly global::System.Windows.Controls.Button button
= new global::System.Windows.Controls.Button();
[global::System.STAThread] public static void Main()
{ var window = new global::System.Windows.Window();
window.Title = "Programmbeispiel";
textBox.FontSize *= 4;
textBox1.FontSize *= 4;
button.FontSize *= 4;
button.Content = "Verdoppeln!";
button.Click += new global::System.Windows.RoutedEventHandler( ButtonClick );
var stackPanel
= new global::System.Windows.Controls.StackPanel();
stackPanel.Orientation = global::System.Windows.Controls.Orientation.Vertical;
stackPanel.Children.Add( textBox );
stackPanel.Children.Add( button );
stackPanel.Children.Add( textBox1 );
window.Content = stackPanel;
window.Show();
new global::System.Windows.Application().Run(); }
static void ButtonClick
( global::System.Object @object, global::System.EventArgs args )
{ textBox1.Text =
global::System.Convert.ToString
( global::System.Convert.ToInt32
( textBox.Text )* 2 ); }}

Seiteninformationen und Impressum   |   Mitteilungsformular  |   "ram@zedat.fu-berlin.de" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram.   |   Eine Verbindung zur Stefan-Ram-Startseite befindet sich oben auf dieser Seite hinter dem Text "Stefan Ram".)  |   Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram. Schlüsselwörter zu dieser Seite/relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram723345 stefan_ram:723345 WPF mit C# Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd723345, slrprddef723345, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram.
https://www.purl.org/stefan_ram/pub/wpf_csharp