2. 오픈에스지
• OpenSG
• 기술이사
• 본 사 : 충남 아산
• 연구소 : 서울 강남
• Solution, Consulting, SI and Education Service based on Microsoft .NET
Technology
• 제조 자동화 설비, 실시간 모니터링, UX
14:30:38
3. Its all about UWP
(UWP : Universal Windows Platform)
1. XAML
2. Tool
3. Databinding
Agenda
14:30:38
14. Adaptive UI
• Visual States
• XAML 정의
• 블랜드를 통해서 정의 가능
• 복잡하게 정의된 효과를 단순하게 선언하여 사용
• 에니메이션, 객체상태…
14:30:39
15. VisualState 상태 전환 방법
• VisualStateManager.Goto(element, state, transition)
private void Page_SizeChanged(object sender, SizeChangedEventArgs
e)
{
var state = string.Empty;
if (e.NewSize.Width > 361)
state = "MinWidth360";
else
state = "MinWidth000";
VisualStateManager.GoToState(this, state, true);
}
14:30:39
20. X:Phase rendering
• 기본값 0
• 작은 값->큰값 순서로 랜더링 수행
• 값이 연속적일 필요는 없음
<DataTemplate x:DataType="model:Monster">
<Grid Width="200" Height="80">
<TextBlock Text="{x:Bind Name}" />
<TextBlock Text="{x:Bind StarSign}" x:Phase="1"/>
</Grid>
</DataTemplate>
14:30:39
21. deferred loading
• 초기 로드되는 요소 최소화
• 요소가 요구되기 전까지는 loading 되지 않는다
• 요소가 요구되는 상황
1. FindName()
2. GetTemplatedChild() (ControlTemplate 일경우)
3. Storyboard & VisualStates (내부적으로 FindName호출함)
<StackPanel x:Name="AdditionalProductPage" x:DeferLoadStrategy="Lazy">
<!– your lovely XAML goes here-->
</StackPanel>
14:30:39
29. Classic Binding
• 장점
• DataContext의 형식이 특정되지 않아도 됨
• 사용이 용이
• 다양하고 유연하게 코드적용가능
• 단점
• 런타임시 타입검사필요->성능이슈
• 디버깅의 어려움
ID
FirstName
LastName
Age
Btype Class
Address
Phone Number
Company
FirstName
Atype Class
Address
Phone Number
Company
Ctype Class
<Page>
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<TextBox Text="{Binding FirstName}" />
…
(object)
DataContext
14:30:39
32. 컴파일 바인딩
• Compiled binding, {x:Bind}, {Binding ….}
• 기존 바인딩 단점
• 런타임시 부하 발생
• 바인딩식 디버깅 어려움
• 바인딩식 컴파일시에 검증 불가능
• 바인딩 대상의 형(Type) 명시 할 수 있다면
• 기존 바인딩 단점 보완 가능
• 런타임시 부하는 적음
• 변환된 코드는 디버깅 가능
• 바인딩식은 컴파일타임에 즉시 검증됨
• 바인딩 선언은 코드로 자동 변환된 후 컴파일 됨
• 기존의 기능과 편리함을 유지 & 성능 향상
14:30:39
33. 컴파일 바인딩
• 바인딩 대상
• DataContext,
• 해당 페이지의 멤버만 바인딩 가능
14:30:39
34. 컴파일 바인딩
<Page x:Class="Demo_Databinding.View.ClassicBindingPage1">
<Grid Background="{StaticResource>
<TextBox Text="{x:Bind sViewModel.PersonInfo.Age}" />
<TextBox Text="{x:Bind sViewModel.PersonInfo.LastName}" />
<TextBox Text="{x:Bind sViewModel.PersonInfo.FirstName}" />
<CheckBox IsChecked="{x:Bind sViewModel.PersonInfo.IsFemale}" />
…
public sealed partial class CompiledBindingPage : Page
{
public SampleViewModel sViewModel { get; set; }
public CompiledBindingPage()
{
this.InitializeComponent();
sViewModel = new SampleViewModel();
}
}
14:30:39
38. 컴파일 바인딩
• 이벤트 바인딩
<Button Click="btnSelectEmployee_Click">사원 정보 선택</Button>
<Button Click="{x:Bind Select}">사원 정보 선택</Button>
14:30:40
39. 컴파일 바인딩
• 이벤트 바인딩
• 적용 가능한 함수 시그니처
• void Select()
• void Select(object sender, RoutedEventArgs e)
• void Select(object sender, object e)
• 오버로딩은 지원되지 않는다->하나의 메서드만 존재해야 함
• 모든 이벤트에 적용 가능함
• ICommand & EventToCommand 대신 사용 가능함
• 인자 전달, CanExecute와 같은 기능은 포함하지 않음
<Button Click="{x:Bind Select}">사원 정보 선택</Button>
<Button Click="{x:Bind EmplyeeUtil.Select}">사원 정보 선택</Button>
14:30:40
40. 컴파일 바인딩
• 바인딩은 컴파일시에 검증된다
• Strongly-typed 바인딩
• 리플렉션을 사용하지 않는다
• 페이지 자신의 멤버를 바인딩
• DataContext와는 무관함
• 기본 모드는 OneTime
• Classic Binding에서는 OneWay가 기본 모드임
• 기존의 OneWay, TwoWay 모드도 가능함
• 기타 표준 바인딩 원리 준수
• INotifyPropertyChanged
• INotifyCollectionChanged
• IObservableVector
14:30:40
41. 컴파일 바인딩 : 고려할 점
• MVVM에서 적용?
• View와 ViewModel과의 coupling 문제
• View 수준에서 ViewModel을 멤버로 가지고 있어야 함
• JSON객체 혹은 untyped object일 경우 사용불가
• Classic Binding을 사용
• 스타일에서의 사용
• {x:Bind}은 style에서 setters 로는 사용 불가
• {x:Bind}은 style에 정의된 DataTemplate 에서는 사용가능
14:30:40
42. {Binding} {x:Bind} 동시사용
• {Binding} {x:Bind} 를 동시에 C# 코드 구성사용 하게 구성
• DataContext와 특정멤버(ViewModel)를 같이 설정함
• XAML에서 {Binding}, {x:Bind}중 어느것을 사용하더라고 동작
public sealed partial class CompiledBindingPage : Page
{
public SampleViewModel sViewModel { get; set; }
public CompiledBindingPage()
{
this.InitializeComponent();
this.DataContextChanged += (s, e) =>
{
sViewModel = DataContext as SampleViewModel;
};
}
}
14:30:40