Download presentation
Presentation is loading. Please wait.
Published byEdward Poole Modified over 9 years ago
1
C# Events and WPF #W5
3
Horizontal Prototype
4
WPF Designed for rapid user interface design Used for many devices: Windows Phone, Tablets, PCs,
5
Microsoft Virtual Academy http://www.microsoftvirtualacademy.com/ M icrosoft Developer Network https://msdn.microsoft.com/
6
Extensible Application Markup Language (XAML) Separating front-end from back-end Design space Tree-like structure Containers; Canvas, Grid, StackPanel UIElements; Image, Button, Rect
7
Some containers Grid Canvas StackPanel
8
Exercise Create a WPF project Create a button in XAML Now create a button in C#
9
C# code… public MainWindow() { InitializeComponent(); Button button1 = new Button(); button1.Content = "Button"; button1.Click += Button_Click; this.Grid1.Children.Add(button1); } private void Button_Click(object sender, RoutedEventArgs e) { throw new NotImplementedException(); } // and add a Click event hanler.
10
Events – – –
11
– –
12
Events
13
Exercise Add Mouse is Up event to the button you just created Change the content to “clicked”
14
Solution private void MouseIsUp(object sender, MouseButtonEventArgs e) { bt.Content = "Clicked"; }
15
Exercise
16
Solution
17
… private void Button_Click(object sender, RoutedEventArgs e) { greetingOutput.Text = "Hello, " + nameInput.Text + "!"; }
18
Timer
19
C# using System.Windows.Threading; public void DispatcherTimerSample() { InitializeComponent(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += timer_Tick; timer.Start(); } void timer_Tick(object sender, EventArgs e) { lblTime.Content = DateTime.Now.ToLongTimeString(); }
20
XAML
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.