40 likes | 193 Views
Windows Presentation Foundation. (WPF). XAML & WPF. XAML element corresponds to a WPF class Element's attributes have corresponding property/event in the class. Example , <Button Background="Red"> No </Button> Or use C #: Button btn = new Button();
E N D
XAML & WPF • XAML element corresponds to a WPF class • Element's attributes have corresponding property/event in the class. • Example, <Button Background="Red"> No </Button> • Or use C#: Button btn = new Button(); btn.Background= Brushes.Red; btn.Content= "No";
WPF example – part 1 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SDKSample.AWindow" Title="Window with Button" Width="250" Height="100"> <!-- Add button to window --> <Button Name="button" Click="button_Click">Click Me! </Button> </Window> • x:Class associates • XAML def'n of window (above) • code-behind class (Awindow) on next slide • This example (pars 1 & 2) is from: http://msdn.microsoft.com/en-us/library/aa970268(v=vs.110).aspx
WPF example –part 2 using System.Windows; // Window, RoutedEventArgs, MessageBox namespace SDKSample { public partial class AWindow: Window { public AWindow() { // InitializeComponent call is required to merge the UI // that is defined in markup with this class, including // setting properties and registering event handlers InitializeComponent(); } void button_Click(object sender, RoutedEventArgs e) { // Show message box when button is clicked MessageBox.Show("Hello, from WPF app!"); } } }