윈도우 앱개발을 향하여

블로그 이미지
윈도우 10 스토어에 앱을 개발해 올리는 것을 목표로 하고 있습니다. 비전공자가 독학으로 시도하는 일이어서 얼마나 걸릴지 모르겠지만... 아무튼 목표는 그렇습니다!!
by 코딩하는 경제학도
  • Total hit
  • Today hit
  • Yesterday hit

Copyright

이 모든 내용은 Pluralsight에 Kevin Dockx가 올린 'XAML Jumpstart : Getting Started With XAML' 이라는 강의의 5번째 챕터를 듣고 정리한 것입니다(https://app.pluralsight.com/library/courses/xaml-jumpstart/table-of-contents). 강의 원작자분께 게시허가도 받았습니다.

#주의 이 강의가 나온 시점에는 x:Bind가 없던 시점이어서 Runtime Binding에 대한 내용만을 다루고 있습니다.


Content

1. Basic Elements, Shapes, Brushes, and Masks

2. Control Basics and Interacting with them

3. Panels and the Layout System

4. Data Binding Essentials

5. Working with ItemsControls

6. Using Resources and Styling Controls

7. Debugging and Analyzing XAML

8. Choosing the Right Tool for the Job




Source : Data Model (like Person)

Source property (ex Name property inside Person class)


Target : UI (like TextBlock)

Target property (ex Text property inside TextBlock) : Target property must be a dependency property


Dependency property is a property that provides a way to compute a value of a property based on the value of other inputs.



On DataContext and Scope

The DataContext property is defined on FrameworkElement. It's the data source used for data binding.

DataContext가 지정되어 있지 않으면 자신의 parent를 따라 DataContext를 찾아 검색하며 올라간다(root element까지, 보통 Page).



Binding Modes

The binding mode allows us to specify how we want to sync between source and target.


OneWay, TwoWay, OneWayToSource, OneTime


Notifying the UI

The UI isn't auto-notified of a change on a backing class.

To allow reporting change

Implement INotifyPropertyChanged on the Model

Raise the PropertyChanged event to notify the UI



Controlling Sync Timing : UpdateSourceTrigger

For binding modes that update the source, we can specify the timing of these updates with the UpdateSourceTrigger property in the binding markup.


ex TexBox-based controls

타자를 칠때마다 Updating하는건 성능을 크게 저하시킨다, 게다가 Update되기 전에 사용자가 오타를 수정할 기회마저 박탈한다. 따라서, the default UpdateSource behavior for text boxes, or text box-based controls, is LostFocus and not PropertyChanged. 이 방법이 대체로 적합하지만 상황에 다라 UpdateSourceTrigger을 통해 이 default behavior를 다른 방식으로 변경할 수 있다.


public enum UpdateSourceTrigger

{

Defualt = 0, PropertyChanged = 1, Explicit = 2, LostFocus = 3

}


(Explicit : when UpdateSource method is called from code)


+ To get binding expression for a certain FrameworkElement => GetBindingExpression method in which we can pass in the dependency property we want to get the binding expression from.


ex private void Button_Click(object sender, RoutedEventArgs e)

{

BindingExpression be = nameOfTextBox.GetGindingExpression(TextBox.TextProperty);

be.UpdateSource();

      }



Converters

A value converter allows us to provide custom logic to a binding to convert from source to target type (and back), so we can bind between properties that have incompatible types.


1. Create a class implementing IValueConverter

2. Implement Convert, and optionally ConvertBack

Convert is used to convert a passed in value to a value of the type of the target property we're binding to.

3. Assign an instance of the class to the Converter property of the Binding markup extension


ex   public class AgeToVisibilityConverter : IValueConverter

{

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

//value = age of Person class, parameter is comes from ConverterParameter in Binding markup extension

{

int.TryParse(value.ToString(), out int age);

int.TryParse(parameter.ToString(), out int maxAge);


return age < maxAge ? Visibility.Visible : Visibility.Collapsed;

}

}


Add an instance of this AgeTovisibilityConverter through Page.Resource dictionary

<Page.Resources>

<local:AgetToVisibilityConverter x:Key="AgeToVisConv" />

<Page.Resources>



Summary (생략)


출처

이 모든 내용은 Pluralsight에 Kevin Dockx가 올린 'XAML Jumpstart : Getting Started With XAML' 이라는 강의의 5번째 챕터를 듣고 정리한 것입니다(https://app.pluralsight.com/library/courses/xaml-jumpstart/table-of-contents). 제가 정리한 것보다 더 많은 내용과 Demo를 포함하고 있으며 최종 Summary는 생략하겠습니다. Microsoft 지원을 통해 한달간 무료로 Pluralsight의 강의를 들으실 수도 있습니다.

'Programming > XAML' 카테고리의 다른 글

(XAML)Using Resources and Styling Controls  (0) 2017.12.12
(XAML)Working with ItemsControls  (0) 2017.12.11
(XAML)Panels and the Layout System  (0) 2017.12.08
(XAML)Control Basics and Interaction with them  (0) 2017.12.07
(XAML)Basic elements  (0) 2017.12.07
AND

ARTICLE CATEGORY

분류 전체보기 (56)
Programming (45)
MSDN (4)
개발노트 (2)
reference (5)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

ARCHIVE