V 1.0 Programming III. XML XAML Data Binding I.. V 1.0ÓE-NIK, 2014 XML (w3schools.com) A hierarchical way of defining data XML declaration + elements.

Slides:



Advertisements
Similar presentations
Ali Alshowaish w3schools. XML documents use a self-describing and simple syntax: The first line is the XML declaration. It defines the XML version (1.0)
Advertisements

SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
Data Binding in GUI Application Development Patrick O’Brien.
Dinko Jakovljević Microsoft Student Partner | BambooLab
VBA Modules, Functions, Variables, and Constants
Programming Based on Events
XML Primer. 2 History: SGML vs. HTML vs. XML SGML (1960) XML(1996) HTML(1990) XHTML(2000)
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
V 1.0 Programming III. Creation of additional windows Routed events.
Pemrograman Berbasis WEB XML -Aurelio Rahmadian- Sumber: w3cschools.com.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.
Next Generation for Desktop Applications Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
1 Intro XAML Attribute syntax & property syntax Panels Reusable resources Controls Data binding Steen Jensen, spring 2014.
V 1.1 Programming III. GUI APIs WPF Hello World Important UI elements UI elements / content models UI elements / inheritance.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.
V 1.1 Programming III. Important events, properties, methods of UI elements XAML basics.
ASP.NET Web Server Controls Basic Web Server Controls.
V 1.0 Programming III. Comparison of GUI APIs WPF Hello World UI elements Content models Inheritance chains.
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
LAYOUT CONTROLS. XAML Overview XAML : eXtensible Application Markup Language pronounced (ZAMEL) is a markup language used to design user interfaces XML-based.
1 XML An Overview Roger Debreceny University of Hawai`i Skip White University of Delaware XBRL Workshop, August 2006.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Chapter 5: Windows and Frames
WEB APPLICATION DEVELOPMENT For More visit:
Consuming eXtensible Markup Language (XML) feeds.
Svetlin Nakov Telerik Corporation
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
More exercises with C# Fateme Rajabi #W6. Add an image to your project Right click on your project name in solution explorer Add -> Existing item -> browse.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
V 1.0 Programming III. Converters Resources. V 1.0ÓE-NIK, 2014 Converters Data conversion: –Can be automatic! E.g.: SolidColorBrush  string, int  string.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
1 Catching up on Rich Clients (round 1) Mike Ormond, Mike Taulty Developer & Platform Group Microsoft Ltd
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
V 1.0 Programming III. XAML Data Binding I.. V 1.0ÓE-NIK, 2014 XAML namespaces Namespaces define the allowed tags and attributes The one without the prefix.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
XML Extensible Markup Language
XML Introduction to XML Extensible Markup Language.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Soyatec Contents Needs Architecture XAML fundamentals Data Binding Advanced features Style Q&A.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Data Binding, Binding Properties Doncho Minkov Telerik School Academy Technical Trainer
Programming III. XAML basics.
Jim Fawcett, Brown Bag Seminar Series Fall 2007
Unit 4 Representing Web Data: XML
Jim Fawcett, Brown Bag Seminar Series Fall 2007
XAML User Interface Creation in C#
Chapter 7 Representing Web Data: XML
.NET and .NET Core 7. XAML Pan Wuming 2017.
An introduction to MVVM using WPF NISCHAL S
Review Session Biggest discrepancy questions
Review of XML IST 421 Spring 2004 Lecture 5.
Presentation transcript:

V 1.0 Programming III. XML XAML Data Binding I.

V 1.0ÓE-NIK, 2014 XML (w3schools.com) A hierarchical way of defining data XML declaration + elements + attributes –Elements:,, … –Attributes: -ban category=„…” … 2 Everyday Italian Giada De Laurentiis Learning XML Erik T. Ray

V 1.0ÓE-NIK, 2014 XML Strict parser rules –First line: optional format descriptor with character encoding: –Every element can contain: Text content or sub elements Attributes –There has to be a root element without sibling (in this example, the element) –Every tag must be closed ( vagy ) Every tag must be properly nested BAD: GOOD: –Case sensitive Everything depends on the interpretation 3

V 1.0ÓE-NIK, 2014 XAML (eXtensible Application Markup Language) XML-based description of object states and hierarchy between.NET objects –We can use classes that can be instantiated and that contain a default constructor Anything that is in the XAML can also be expressed in C# In WPF we use XAML to build our GUI During the compile process –msbuild.exe will compile it into binary data, then add the data as a resource into the assembly–.g.cs ->.baml –The InitializeComponent() will load it 4

V 1.0ÓE-NIK, 2014 XAML XAML format: C# format: In XAML, the elements mean creation of an instance The attributes specify the properties/events 5 <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;

V 1.0ÓE-NIK, 2014 XAML – setting the textual content With an attribute: sub-element: As a text sub-element A XAML specifikációja szerint: minden osztály deklarálhat „tartalomtulajdonságot” (Content Property) – ekkor a közvetlen gyermekelem ennek a beállítására szolgál. A ContentControloknál ez a „tartalomtulajdonság” a Content… 6 <CheckBox Content="Automatikus mentés" Name="checkBox1" IsChecked="True"/> Automatikus mentés Automatikus mentés

V 1.0ÓE-NIK, 2014 XAML – setting the complex content As a sub-element sub-element Syntax error – The Scrollbar is not a ContentControl, there is no Content 7 Automatikus mentés Automatikus mentés Automatikus mentés

V 1.0ÓE-NIK, 2014 XAML – setting the complex content … with ItemsControl descendants, sub-elements go into the Items (Collection Syntax) … with Panel (content managers), sub-elements go into the Children 8 Gyűjteményszintaxis (Collection Syntax)

V 1.0ÓE-NIK, 2014 XAML Attached Property Syntax 9

V 1.0ÓE-NIK, 2014 XAML namespaces XML namespaces define the allowed xml tags and attributes and keywords 10 <Window x:Class="WpfApplication4.MainWindow” xmlns=" xmlns:x=" Title="MainWindow" Height="350" Width="525">

V 1.0ÓE-NIK, 2014 XAML namespaces WPF-centered.NET namespaces are imported: –System.Windows –System.Windows.Controls –System.Windows.Data –System.Windows.Media –System.Windows.Navigation... stb. This is the default namespace, no need for extra namespace prefix: 11 <Window x:Class="WpfApplication4.MainWindow” xmlns=" xmlns:x=" <Window x:Class="WpfApplication4.MainWindow” xmlns=" xmlns:x=" Title="MainWindow" Height="350" Width="525">

V 1.0ÓE-NIK, 2014 XAML namespaces XAML-specific keywords and the System.Windows.Markup types are imported: –Class, Null, Static, Array, ClassModifier, FieldModifier, DynamicResource, StaticResource, Key, Name, Code, … We will use only a few special keywords from this namespace We have to use the namespace prefix for these keywords (usually, x:Something ) 12 <Window x:Class="WpfApplication4.MainWindow” xmlns=" xmlns:x=" <Window x:Class="WpfApplication4.MainWindow” x:ClassModifier="internal" xmlns=" xmlns:x=" Title="MainWindow" Height="350" Width="525"> <Button Content="START!" Name="buttonStart” x:FieldModifier="public"/>

V 1.0ÓE-NIK, 2014 XAML namespaces Import a custom.NET namespace –clr-namespace: namespace_name –assembly: the executing assembly that contains the namespace, typically.exe/.dll file without the extension –Refer to the documentation: 13 <Window x:Class="WpfApplication4.MainWindow"... xmlns:System="clr-namespace:System;assembly=mscorlib”> Hello World

V 1.0ÓE-NIK, 2014 XAML markup extensions Assign special, highly complex values for a XAML attribute, usually defined as string and converted into a primitive/complex type Customize behaviour: –Use Null –Assign an already existing object –Assign a static value –We want to use a type that does not have a default parameterless constructor –etc. Format: For every attribute, the allowed keywords between the {} letters are different – must be careful! 14 Property="{…}"

V 1.0ÓE-NIK, 2014 Data binding I. Connect any property of a GUI element to another instance –When the instance changes, the GUI should change as well –When the GUI changes, the instance should change as well –MVVM, we will almost use MVVM E.g.: –Display the data of a person: textBoxName.Text  person.Name checkBoxOnHoliday.IsChecked  person.OnHoliday checkBoxSick.IsChecked  person.Sick 15

V 1.0ÓE-NIK, 2014 Data binding I. E.g.: –Volume slider label.Content  slider.Value E.g. : –Set the enabled property of multiple controls based on a single checkbox radioButtonXXX.IsEnabled  checkBox.IsChecked OR: stackPanel.IsEnabled  checkBox.IsChecked 16

V 1.0ÓE-NIK, 2014 Data binding I. E.g. : –Display certain elements in a listbox listBox.ItemsSource  tömb E.g. : –Change the border based on the selected item listBox.BorderBrush  listBox.SelectedItem E.g. : –Display extra data about the selected item labelXXXX.Content  comboBox.SelectedItem.XXXX 17

V 1.0ÓE-NIK, 2014 Data Binding I. Every data binding has a source and a target –The source is where the data is stored, it has to be a public property of any class –The target is usually a property of a GUI element that will use the data The target must be a Dependency Property The target class must be a DependencyObject descendant 18 E.g. : –Display the data of a person: –textBoxName.Text  person.Name –Source: person.Name –Target: textBoxName.Text

V 1.0ÓE-NIK, 2014 Data Binding I. XAML using the {Binding} markup extension –ElementName: if the source is another UI element –Path: the name of the property inside the source –Alternative syntax Equivalent to the following C# code (NEVER USE) –E.g. in the constructor or in the Loaded event handler 19 <TextBox Name="textBoxToEnable" IsEnabled="{Binding ElementName=checkBoxEnabled, Path=IsChecked}" /> textBoxToEnable.SetBinding(TextBox.IsEnabledProperty, new Binding("IsChecked") { Source = checkBoxEnabled }); "{Binding IsChecked, ElementName=checkBoxEnabled}"

V 1.0ÓE-NIK, 2014 Data Binding I. – Defining paths Simple property inside the source: –ElementName=checkBoxEnabled, Path=IsChecked Property of a property: –ElementName=listBox, Path=SelectedItem.Name Indexer property: –ElementName=listBox, Path=Items[0] 20

V 1.0ÓE-NIK, 2014 Data Binding I. - DataContext Default source of a data binding The DataContext is a dependency property, so its value can be “received/inherited” from the parent UI element / XAML tag –We use this quite often: 21 <Label Content="{Binding Age}"

V 1.0ÓE-NIK, 2014 Data Binding I. - DataContext We can set the DataContextet from C# code: –XAML code: –Setting the source: 22 <Label Content="{Binding Age}" Szemely sz = new Szemely("Péter", 12, "Magyarország", "Budapest"); stackPanel.DataContext = sz;

V 1.0ÓE-NIK, 2014 Data Binding I. - DataContext Sometimes we specify a Data Binding to a whole object –Path is not present or Path=. –The whole DataContext is used –Automatic ToString() is called  not advised 23 public override string ToString() //Személy osztály ToString() { return nev + " (" + szuletesiEv + ")"; } public MainWindow() { InitializeComponent(); this.DataContext = new Szemely() { Nev = "Peti", SzuletesiEv = 1985 }; }

V 1.0ÓE-NIK, 2014 Data Binding I. Possible directions –OneWay, TwoWay, OneWayToSource, OneTime –OneWay: the change in the source will change the target, the target will not change the source –OneWayToSource: the change in the target will change the source, the source will not change the target –TwoWay: vice-versa –OneTime: one-time initialization from source to target, no synchronization is done afterwards 24 <TextBox Text="{Binding Value, ElementName=slider, Mode=TwoWay}"

V 1.0ÓE-NIK, 2014 Data Binding I. When to update the source? –If the direction is TwoWay or OneWayToSource –LostFocus (default for TextBox) –PropertyChanged (usually default) –Explicit: only if UpdateSource() is called –Default (LostFocus/ProperyChanged/Explicit) 25 <TextBox Text="{Binding Value, ElementName=slider, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

V 1.0ÓE-NIK, 2014 Searching for errors... We get notifications only in the Output window and only when the data is actually requested –No exception is thrown –Use trace: –Same message for bad names and non-public properties! 26

V 1.0ÓE-NIK, 2014 Exercise – music playlist manager 27