개발자가 알아야할 Binding 강남 DataBinding 스타일 Windows 8 앱개발자라면 꼭 알아야할.

Slides:



Advertisements
Similar presentations
Patterns & practices Symposium 2013 Tips for building a Windows Store app using XAML and C#: The Kona project Francis Cheung
Advertisements

Data Binding in GUI Application Development Patrick O’Brien.
Dinko Jakovljević Microsoft Student Partner | BambooLab
WinRT Apps
Crossword Puzzle Solver Michael Keefe. Solver structure.
WinFX – A Lap Around the Windows Presentation Foundation Bart J.F. De Smet MVP Visual C#
Charles Petzold Controls and Data Binding.
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.
V 1.0 Programming III. Creation of additional windows Routed events.
CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last.
Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.
WinRT Apps 29 April 2014 Building Apps for Windows Phone 8.1 Jump Start.
Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no.
1 Intro XAML Attribute syntax & property syntax Panels Reusable resources Controls Data binding Steen Jensen, spring 2014.
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Xamarin.Forms Hands On.
Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.
Copyright © 2006 Thomas P. Skinner1 Chapter 5 Indexers, Interfaces, and Enumerators.
Adam Calderon – C# MVP Application Development Practice Lead Interknowlogy.
V 1.1 Programming III. Creating additional windows Event handling: preview/routed events.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
Modern Design Principles (MS). Back in the days This was how an RSS reading application looked like.. In Modern Design it would look like..
LAYOUT CONTROLS. XAML Overview XAML : eXtensible Application Markup Language pronounced (ZAMEL) is a markup language used to design user interfaces XML-based.
Introduction to Building Windows 8.1 & Windows Phone Applications.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Modern Software Development Using C#.NET Chapter 5: More Advanced Class Construction.
Mail RIA & Silverlight – Defining new experience on the Web Our RIA objectives - Eric Hoffman A Silverlight development tale – Eric Hoffman A new verse.
Windows Phone MVVM and Unit Testing Step by Step Andy Wigley Windows Phone Development MVP, Mobile Software Consultant APPA Mundi Ltd WPH208.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Сергей Пугачёв Microsoft Silverlight 5, XAML и связывание данных.
КРУПНЕЙШАЯ ТЕХНИЧЕСКАЯ КОНФЕРЕНЦИЯ MICROSOFT В УКРАИНЕ Metro приложения: работа с данными Краковецкий Александр, MVP/RD/PhD. DevRain Solutions.
Object Oriented Software Development 10. Persistent Storage.
Svetlin Nakov Telerik Corporation
Module 7 Data Binding to Collections. Module Overview Binding to Collections of Objects Using Collection Views Create Master-Detail User Interfaces Using.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
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.
ControlTemplate and DataTemplate Doncho Minkov Telerik School Academy Technical Trainer
Module 3 Designing and Developing a User Interface.
Advanced Technology Days 18. i 19. studenog 2015., Cinestar Arena Centar.
1 Catching up on Rich Clients (round 1) Mike Ormond, Mike Taulty Developer & Platform Group Microsoft Ltd
.NET Framework Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer Cornerstone
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
WPF Data Binding Tomer Shamam Smart Client Team Leader Sela Group
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
New for dependency properties register for property changes.
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.
V 1.0 Programming III. Visual/FrameworkElement descendants.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Windows 8 apps and the MVVM pattern SILVERLIGHTSHOW.NET WEBINARS SERIES GILL CLEEREN, October 16 th
/DEV/TM #1 Building Cross-Platform Apps with Xamarin and MvvmCross Flavius-Radu DEMIAN.
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
In Windows 8 Store Applications
State of the Art in Mobile Development - AndRES Käver, 2016
Ben Riga 02 | Basics of View Models Ben Riga
Avalon – Using Data In Your Applications
03 | Building Windows Store Apps with XAML Part 3
WPF AKEEL AHMED.
البرمجة بلغة الفيجول بيسك ستوديو
An introduction to MVVM using WPF NISCHAL S
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Lists and List Items in Windows Runtime Apps
04 | UI Presentation & XAML
Page Navigation and Data Binding in Windows Runtime Apps
DEV312 基于WPF的数据绑定.
ListView and GridView (2)
CSE775 DO supporting slides for VRTS Client Demo
Bringing existing managed code into Metro style apps
Data/Code driven UI using WPF part 2
Presentation transcript:

개발자가 알아야할 Binding 강남 DataBinding 스타일 Windows 8 앱개발자라면 꼭 알아야할

Non-DataBinding vs. DataBinding TitleText.Text = item.Title; SubTitleText.Text = item.SubTitle; this.DataContext = item;

버튼 누가 지웠어 !

Non-DataBinding vs. DataBinding TitleText.Text = item.Title; SubTitleText.Text = item.SubTitle; 컴파일 에러 발생 !!! this.DataContext = item; 컴파일 에러 없음  UI 와 코드의 분리  개발자와 디자이너 업무영역의 분리  PEACE!

이번 앨범 타이틀 곡이 뭐야 ?

문맥

너랑 나 ! 강남스타일 !

문맥 = Context

DataContext

FrameworkElement.DataContext 거의 모든 UI 는 FrameworkElement

가정 class Album + string CoverArt + string Name + Artist Artist class Artist + string ProfilerImage + string Name class Chart + Album FirstAlbum + List Albums

자식에게 상속하는 DataContext Visual Tree <Grid x:Name=“LayoutRoot” DataContext=“{Binding TopAlbum}”> Grid(LayoutRoot) TextBlock Grid Image TextBlock Image

자식에게 상속하는 DataContext Visual Tree <Grid x:Name=“LayoutRoot” DataContext=“{Binding TopAlbum}”> Grid(LayoutRoot) TextBlock Grid Image TextBlock Image

DataContext 주입법 var chart = GetKPopChart(); this.DataContext = chart; ….. In C# In XAML …..

Binding

문법 Binding –Text="{Binding Title}" Path ( 생략가능 ) –Text=“{Binding Path=Title}” Source –Text=“{Binding Name, Source={StaticResource MyViewModel}}” Converter –Text=“{Binding PublishDate, Converter={StaticResource FamiliarDateString}}” ConverterParameter –Text=“{Binding Price, Converter={StaticResource CurrencyConverter}, ConverterParameter=\{0:C2\}}”

{Binding } DataContext 자기 자신 !

ItemsControl

ItemsControl 가족 ListView GridView FlipView ListBox ComboBox Control ItemsControl Selector ListViewBase ListViewGridView FlipViewListBoxComboBox.ItemsSource 프로퍼티가 여기 정의

ItemsControl 에서 DataContext 분배 var artists = new List () { new Artist() { Name = “ 싸이 ”, CoverArt=“…”}, new Artist() { Name = “ 아이유 ”, CoverArt=“…”}, new Artist() { Name = “ 싸이 ”, CoverArt=“…”}, new Artist() { Name = “ 아이유 ”, CoverArt=“…”}, } this.Artists = artist; …. XAML 에서 CS 에서 싸이 아이유 싸이 아이유

ItemTemplate 과 DataContext new Artist() { Name = “ 싸이 ”, CoverArt=“…”, } ItemsSource 의 인스턴스 하나가 ListViewItem 하나의 DataContext 가 된다. 싸이

In the hood protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { var contentControl = element as ContentControl; contentControl.ContentTemplate = this.ItemTemplate; contentControl.DataContext = item; } ItemsControl 의 virtual PrepareContainerForItemOverride(…) 에서

INotifyPropertyChanged INotifyCollectionChanged

약속 컨트롤은 INotifyPropertyChanged.PropertyChanged 를 구독합니다. 컨트롤은 INotifyCollectionChanged.CollectionChanged 를 구독합니다. public abstract class BindableBase : INotifyPropertyChanged public class ObservableCollection : Collection, INotifyCollectionChanged Common/BindableBase.cs 에서 System.Collections.ObjectModel

이미 구현되어 있는 것 public abstract class SampleDataCommon : App4.Common.BindableBase private string _title = string.Empty; public string Title { get { return this._title; } set { this.SetProperty(ref this._title, value); } } protected bool SetProperty (ref T storage, T value, [CallerMemberName] String propertyName = null) { if (object.Equals(storage, value)) return false; storage = value; this.OnPropertyChanged(propertyName); return true; } DataModel/SampleDataSource.cs 에서 프로퍼티 예 : Title In the Hood

List vs. ObservableCollection this.Artist.Add(new Artist()); 싸이 아이유 싸이 아이유 싸이 아이유

Converter

어떤 필요, 어떤 니즈 ? public List Artists { get; set; } … Artists = new List () { “ 싸이 ”, “ 아이유 ”, }; 너랑 나랑 강남스타일 싸이, 아이유

샘플 ArtistConverter namespace MyApp { public class ArtistConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { // null 체크, value 가 Ienumerable 타입이 아닐 때 예외처리 ( 생략 ) var list = value as IEnumerable; StringBuilder sb = new StringBuilder(); foreach (var item in list) { if (sb.Length > 0) sb.Append(“, “); sb.Append((string)item); } return sb.ToString(); }

사용법 너랑 나랑 강남스타일 싸이, 아이유 인스턴스 생성 ( 어딘가에 ) -> 바인딩 식에서 잘 사용 In MyView.xaml (or App.xaml) … <TextBlock Text=“{Binding Artists, Converter={StaticResource ArtistConverter}”/>

Blend 도와줘 !

Sample Project Code Review

GridApp 샘플 프로젝트에서 protected override void LoadState(Object navigationParameter, Dictionary pageState) { // TODO: Create an appropriate data model for your problem domain to replace the sample data var sampleDataGroups = SampleDataSource.GetGroups((String)navigationParameter); this.DefaultViewModel["Groups"] = sampleDataGroups; } <common:LayoutAwarePage x:Name="pageRoot" x:Class="App4.GroupedItemsPage" DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}“ … <CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Groups}" GroupedItemsPage.xaml.cs 에서 GroupedItemsPage.xaml 에서

FIN 즐거운 해커쏜 (θ) 되세요 !