What kinds of elements are used by WPF as top-level elements:
1. Window element
2. Page Element ( similar to the Window element for navigable applications)
3. Application Element (define application resources and startup settings)
PS: There can be only one top-level element in a WPF Application
1 <Windowx:class= "Wpfapplication2.mainwindow"2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525">5 <Grid>6 7 </Grid>8 </Window>
class is Classes
xmlns is an abbreviation for XML Namespaces , the Chinese name is the XML(a subset of the standard Generic Markup Language) namespace
xmlns[: Optional mapping prefix ]="namespace"
Name the element: (Take the grid element as an example)
Example one:
1 <Windowx:class= "Wpfapplication2.mainwindow"2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525">5 <GridName= "Grid1">6 7 </Grid>8 </Window>
Example two:
1 <Windowx:class= "Wpfapplication2.mainwindow"2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525">5 <Grid>6 <Grid.name>Grid1</Grid.name>7 </Grid>8 </Window>
The above two examples of equivalent
The above is the UI-level code
The logical code level invokes the name attribute of the above grid element as an example:
The following code will change the title of the form to the name attribute of the Grid element (try <Grid.Name>grid1</Grid.Name> Invalid)
UI Layer Code
1 <Windowx:class= "Wpfapplication2.mainwindow"2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525"Loaded= "window_loaded">5 <GridName= "Grid1">6 </Grid>7 </Window>
Logic Layer Code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Windows;7 usingSystem.Windows.Controls;8 usingSystem.Windows.Data;9 usingSystem.Windows.Documents;Ten usingSystem.Windows.Input; One usingSystem.Windows.Media; A usingSystem.Windows.Media.Imaging; - usingSystem.Windows.Navigation; - usingSystem.Windows.Shapes; the - namespaceWpfApplication2 - { - /// <summary> + ///the interactive logic of MainWindow.xaml - /// </summary> + Public Partial classMainwindow:window A { at PublicMainWindow () - { - InitializeComponent (); - } - - Private voidWindow_Loaded (Objectsender, RoutedEventArgs e) in { - This. Title = This. Grid1. Name; to } + } -}
WPF self-paced notes