XAML elmagyarázása előtt tudni kell, mi az az XML… Hierarchical way to describe DATA XML declaration + nodes + attributes Nodes: Download presentation Presentation is loading. Please wait.
1
Programming III. XAML basics
2
XML (w3schools.com) Hierarchical way to describe DATA
3
XML Strict rules apply – well-formed XML! Every node can contain: Text
4
XML The nodes and the attributes can describe an object
5
XAML (eXtensible Application Markup Language)
6
XAML XAML description: C# language:
7
XAML Setting the content explicitly:
8
XAML More complex content Using the Property syntax
9
XAML With the ItemsControl, the immediate children set the Items…
10
XAML Collection Syntax
11
XAML Attached Property Syntax <Grid> <Grid.RowDefinitions>
12
Practice exercise
Similar presentations © 2025 SlidePlayer.com Inc. Log in
Similar presentations
Presentation on theme: "Programming III. XAML basics."— Presentation transcript:
<?xml version="1.0"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </bookstore> XAML elmagyarázása előtt tudni kell, mi az az XML… Hierarchical way to describe DATA XML declaration + nodes + attributes Nodes: <bookstore></bookstore>... = <tag></tag> Attributes: within the <book> category=“…” …
First line: optional format specifier, with definition of encoding : <?xml version="1.0" encoding="ISO "?> <?xml version="1.0" encoding="UTF-8"?> Every node can contain: Text Sub nodes Attributes There has to be exactly one root element (<bookstore>) Closing a tag is obligatory (<tag></tag> or <tag />), with good nesting The whole document is case-sensitive Ezt igazából nem most akarjuk leadni.
<book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> The nodes and the attributes can describe an object Using nesting, we can represent hierarchy – the XML always depends on the interpretation! <?xml version="1.0"?> <bookstore> <book category="COOKING"> ... </book> <book category="WEB"> ... </book> </bookstore>
XML-based language, where we describe the hierarchy and the properties of .NET objects VALID xml !!! (not only well-formed) We can use types that are not abstract and that have a default (zero-parameter) constructor Everything in the XAML could also be written in C# (or other languages in the CLR: language-independent) In the WPF we use it to build up a GUI When compiling a XAML... msbuild.exe attaches it into the assembly as a binary resource – .g.cs -> .baml The InitializeComponent() loads the XAML, which is called in the constructor Szerintem ez úgy néz ki, hogy a XAML-ból keletkezik a .g.cs, és a .xaml.cs és a .g.cs fordul IL kódba, plusz a XAML másik (objektumleíró) részéből keletkezik a .baml. De erre sehol nem találtam konkrét forrást. XAML is used extensively in .NET Framework 3.0 & .NET Framework 4.0 technologies, particularly Windows Presentation Foundation (WPF),Silverlight, Windows Workflow Foundation (WF) and Windows Runtime XAML Framework and Windows Store apps A XAML file can be compiled into a Binary Application Markup Language file having the .BAML extension.[2]), which may be inserted as a resource into a .NET Framework assembly. At run-time, the framework engine extracts the .BAML file from assembly resources, parses it, and creates a corresponding WPF visual tree or workflow. Having this format, the content is faster loadable during runtime. XAML is still parsed and constructed by the runtime Once upon a time, there was CAML. CAML was the exact IL version of the compiled XAML file. Unfortunately, the WPF team has decided to eliminate it, and keep the BAML version for the following reasons: 1. BAML is compact hence it can be downloaded faster (good for XBAP applications) 2. BAML is less security threat than code execution (good for XBAP applications) 3. BAML can be localized after compilation In the bottom line, BAML is a little slower than IL but has more advantages than CAML.
The XAML nodes actually mean the creation of an instance of a .NET class The attributes change the properties / event subscriptions <CheckBox Content="Automatikus mentés" Name="checkBox1" IsChecked="True" Checked="checkBox1_Checked"/> CheckBox checkBox1 = new CheckBox(); checkBox1.Content = "Automatikus mentés"; checkBox1.IsChecked = true; checkBox1.Checked += checkBox1_Checked;
Property syntax: <Typename.Propertyname> sub-node Setting the content implicitly: According to the XAML specs: the immediate children set the Content Property, but this property is not necessary the actual Content (for ItemsControl/Layout managers, the immediate children set the Items/Children property) <CheckBox Content="Automatikus mentés" Name="checkBox1" IsChecked="True"/> <CheckBox Name="checkBox1" IsChecked="True"> <CheckBox.Content> Automatikus mentés </CheckBox.Content> </CheckBox> Basically, ez a pár dia (ez és a következő 3) arról akar szólni, hogy a xamlban látott al-elemek mit jelentenek. És azért pont a content a példa, mert ő egy tartalomtulajdonság is, azaz implicit gyerekkel is megadható -> el lehet vele magyarázni az implicit gyereket... (nem szöveges -> köv dián) With the exception of the root element, every object element in a XAML file that is nested as a child element of another element is really an element that is one or both of the following cases: a member of an implicit collection property of its parent element, or an element that specifies the value of the XAML content property for the parent element (XAML content properties will be discussed in an upcoming section). In other words, the relationship of parent elements and child elements in a markup page is really a single object at the root, and every object element beneath the root is either a single instance that provides a property value of the parent, or one of the items within a collection that is also a collection-type property value of the parent. <CheckBox Name="checkBox1" IsChecked="True"> Automatikus mentés </CheckBox>
Syntax error – this is NOT a ContentControl descendant, there is no Content or anything similar <CheckBox Name="checkBox1" IsChecked="True"> <Button>Automatikus mentés</Button> </CheckBox> <CheckBox Name="checkBox1" IsChecked="True"> <CheckBox.Content> <Button>Automatikus mentés</Button> </CheckBox.Content> </CheckBox> <ScrollBar Name="scrollBar1"> <Button>Automatikus mentés</Button> </ScrollBar>
With layout manaagers, the immediate children set the Children <ListBox > <Button Content="Button" Width="75"/> </ListBox> A pirossal bekeretezett részeken Collection Syntax. <Window ... Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="Button" Width="75" ... /> </Grid> </Window> Collection Syntax
More then one sub-nodes can be specified, if the given property is a collection (IList, Array, IDictionary) ListBox.Items, Grid.Children, etc... <ListBox > <Button Content="Button" Width="75"/> </ListBox> Grid.ColumnDefinitions, Grid.RowDefinitions jó példa olyanra, ami nem tartalomtulajdonság… <Grid> <Grid.RowDefinitions> <RowDefinition Height="1*"/> </Grid.RowDefinitions> ... </Grid>
<RowDefinition Height="107*"/> <RowDefinition Height="115*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="66*"/> <ColumnDefinition Width="67*"/> </Grid.ColumnDefinitions> <Button Content="Button1" Grid.Column="0" Grid.Row="0"/> <Button Content="Button2" Grid.Column="1" Grid.Row="0"/> <Button Content="Button3" Grid.Column="0" Grid.Row="1"/> </Grid> Ezt még azért érdemes említeni, mert: Plusz szükséges a grafikánál (Canvas miatt, X Y koordináta állításnál), llletve abban az esetben, amikor szülőben akarunk kezelni gyerekelemhez tartozó eseményt, amennyiben a szülő nem rendelkezik azzal az eseménnyel. Pl gridben akarjuk kezelni a button clickeket, de a gridnek ugye nincs clickje.
Similar presentations
All rights reserved.