■ BindableObject 엘리먼트의 BindingContext 속성을 사용하는 방법을 보여준다.
▶ 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 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" Padding="10"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Label x:Name="label" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Text="TEXT" /> <Slider x:Name="scaleSlider" Grid.Row="1" Grid.Column="0" BindingContext="{x:Reference label}" Maximum="10" Value="{Binding Scale, Mode=TwoWay}" /> <Label Grid.Row="1" Grid.Column="1" BindingContext="{x:Reference scaleSlider}" VerticalTextAlignment="Center" Text="{Binding Value, StringFormat='확대/축소 = {0:F1}'}" /> <Slider x:Name="rotationSlider" Grid.Row="2" Grid.Column="0" BindingContext="{x:Reference label}" Maximum="360" Value="{Binding Rotation, Mode=OneWayToSource}" /> <Label Grid.Row="2" Grid.Column="1" BindingContext="{x:Reference rotationSlider}" Text="{Binding Value, StringFormat='회전 = {0:F0}'}" VerticalTextAlignment="Center" /> <Slider x:Name="rotationXSlider" Grid.Row="3" Grid.Column="0" BindingContext="{x:Reference label}" Maximum="360" Value="{Binding RotationX, Mode=OneWayToSource}" /> <Label Grid.Row="3" Grid.Column="1" BindingContext="{x:Reference rotationXSlider}" VerticalTextAlignment="Center" Text="{Binding Value, StringFormat='X축 회전 = {0:F0}'}" /> <Slider x:Name="rotationYSlider" Grid.Row="4" Grid.Column="0" BindingContext="{x:Reference label}" Maximum="360" Value="{Binding RotationY, Mode=OneWayToSource}" /> <Label Grid.Row="4" Grid.Column="1" BindingContext="{x:Reference rotationYSlider}" VerticalTextAlignment="Center" Text="{Binding Value, StringFormat='Y축 회전 = {0:F0}'}" /> </Grid> </ContentPage> |