■ PriorityBinding 엘리먼트를 사용해 우선 순위 바인딩을 사용하는 방법을 보여준다.
▶ AsyncSampleDataSource.cs
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
using System.Threading; namespace TestProject { /// <summary> /// 비동기 샘플 데이터 소스 /// </summary> public class AsyncSampleDataSource { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 저속 값 /// </summary> private string slowerValue; /// <summary> /// 최저속 값 /// </summary> private string slowestValue; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 고속 값 - FastValue /// <summary> /// 고속 값 /// </summary> public string FastValue { get; set; } #endregion #region 저속 값 - SlowerValue /// <summary> /// 저속 값 /// </summary> public string SlowerValue { get { Thread.Sleep(3000); return this.slowerValue; } set { this.slowerValue = value; } } #endregion #region 최저속 값 - SlowestValue /// <summary> /// 최저속 값 /// </summary> public string SlowestValue { get { Thread.Sleep(5000); return this.slowestValue; } set { this.slowestValue = value; } } #endregion } } |
▶ MainWindow.xaml
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 32 33 34 35 36 37 38 39 40 41 42 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <local:AsyncSampleDataSource x:Key="AsyncSampleDataSourceKey" SlowestValue="Slowest Value" SlowerValue="Slower Value" FastValue="Fast Value" /> </Window.Resources> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Source={StaticResource AsyncSampleDataSourceKey}}"> <TextBlock HorizontalAlignment="Center" Margin="10" FontSize="18" FontWeight="Bold"> Priority Binding </TextBlock> <TextBlock HorizontalAlignment="Center" Padding="5" Background="Honeydew"> <TextBlock.Text> <PriorityBinding FallbackValue="Default Value"> <Binding Path="SlowestValue" IsAsync="True" /> <Binding Path="SlowerValue" IsAsync="True" /> <Binding Path="FastValue" /> </PriorityBinding> </TextBlock.Text> </TextBlock> </StackPanel> </Window> |