■ CompareStateTrigger 엘리먼트의 Comparison/Value/To 속성을 사용해 값 상태에 따라 처리하는 방법을 보여준다.
※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다.
※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를 None으로 추가했다.
▶ MainPage.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 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
<?xml version="1.0" encoding="utf-8"?> <Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ctw="using:CommunityToolkit.WinUI" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup> <VisualState x:Name="Less"> <VisualState.StateTriggers> <ctw:CompareStateTrigger Comparison="LessThan" Value="{Binding Value, ElementName=slider1, Mode=OneWay}" To="3" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="statusTextBlock1.Text" Value="Slider value is less than 3" /> </VisualState.Setters> </VisualState> <VisualState x:Name="Equal"> <VisualState.StateTriggers> <ctw:CompareStateTrigger Comparison="Equal" Value="{Binding Value, ElementName=slider1, Mode=OneWay}" To="3" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="statusTextBlock1.Text" Value="Slider value is 3" /> </VisualState.Setters> </VisualState> <VisualState x:Name="Greater"> <VisualState.StateTriggers> <ctw:CompareStateTrigger Comparison="GreaterThan" Value="{Binding Value, ElementName=slider1, Mode=OneWay}" To="3" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="statusTextBlock1.Text" Value="Slider value is greater than 3" /> </VisualState.Setters> </VisualState> </VisualStateGroup> <VisualStateGroup> <VisualState x:Name="GreaterThanOrEqual"> <VisualState.StateTriggers> <ctw:CompareStateTrigger Comparison="GreaterThanOrEqual" Value="{Binding Value, ElementName=slider2, Mode=OneWay}" To="4" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="statusTextBlock2.Text" Value="Slider value is 4 or greater" /> </VisualState.Setters> </VisualState> <VisualState x:Name="LessThanOrEqual"> <VisualState.StateTriggers> <ctw:CompareStateTrigger Comparison="LessThanOrEqual" Value="{Binding Value, ElementName=slider2, Mode=OneWay}" To="2" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="statusTextBlock2.Text" Value="Slider value is 2 or less" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" MaxWidth="400"> <Slider Name="slider1" Width="300" Minimum="0" Maximum="5" /> <TextBlock Name="statusTextBlock1" Style="{StaticResource CaptionTextBlockStyle}" Margin="0 10 0 0" Text="If you see this, trigger isn't working" /> <Slider Name="slider2" Width="300" Margin="0 30 0 0" Minimum="0" Maximum="5" /> <TextBlock Name="statusTextBlock2" Style="{StaticResource CaptionTextBlockStyle}" Margin="0 10 0 0" Text="Slider value is 3" /> </StackPanel> </Grid> </Page> |