Zadanie
13 listopada 2025
<StackLayout>
<StackLayout WidthRequest="900" HeightRequest="900">
<StackLayout x:Name="jola"
Orientation="Horizontal"
WidthRequest="800"
HeightRequest="150">
<Label Text="Jola" FontSize="40" Margin="0,30"/>
<StackLayout Margin="150,0">
<Label Text ="INF.03" FontSize="30" HorizontalTextAlignment="Center"/>
<Entry x:Name="inf03Jola" WidthRequest="200"
HorizontalTextAlignment="Center"/>
</StackLayout>
<StackLayout>
<Label Text ="INF.04" FontSize="30" HorizontalTextAlignment="Center"/>
<Entry x:Name="inf04Jola" WidthRequest="200"
HorizontalTextAlignment="Center"/>
</StackLayout>
</StackLayout>
<StackLayout x:Name="Edek"
Orientation="Horizontal"
WidthRequest="800"
HeightRequest="150">
<Label Text="Edek" FontSize="40" Margin="0,30"/>
<StackLayout Margin="110,0">
<Label Text ="INF.03" FontSize="30" HorizontalTextAlignment="Center"/>
<Entry x:Name="inf03Edek" WidthRequest="200" MaxLength="1"
HorizontalTextAlignment="Center" TextChanged="funkcja1">
<Entry.Triggers>
<DataTrigger TargetType="Entry"
Binding="{Binding Source={x:Reference inf03Edek},
Path=Text}"
Value="0" >
<Setter Property="BackgroundColor"
Value="Red"/>
<Setter Property="TextColor"
Value="White"/>
</DataTrigger>
<DataTrigger TargetType="Entry"
Binding="{Binding Source={x:Reference inf03Edek},
Path=Text}"
Value="1" >
<Setter Property="BackgroundColor"
Value="Green"/>
<Setter Property="TextColor"
Value="White"/>
</DataTrigger>
</Entry.Triggers>
</Entry>
<Label x:Name="komunikat" Text="Musisz wskazać liczbę 0 lub 1 !"/>
</StackLayout>
<StackLayout>
<Label Text ="INF.04" FontSize="30" HorizontalTextAlignment="Center"/>
<Entry x:Name="inf04Edek" WidthRequest="200"
HorizontalTextAlignment="Center"/>
</StackLayout>
</StackLayout>
<StackLayout x:Name="filemon"
Orientation="Horizontal"
WidthRequest="800"
HeightRequest="150">
<Label Text="Filemon" FontSize="40" Margin="0,30"/>
<StackLayout Margin="50,0">
<Label Text ="INF.03" FontSize="30" HorizontalTextAlignment="Center"/>
<Entry x:Name="inf03filemon" WidthRequest="200"
HorizontalTextAlignment="Center"/>
</StackLayout>
<StackLayout>
<Label Text ="INF.04" FontSize="30" HorizontalTextAlignment="Center"/>
<Entry x:Name="inf04filemon" WidthRequest="200"
HorizontalTextAlignment="Center"/>
</StackLayout>
</StackLayout>
</StackLayout>
</StackLayout>
public MainPage()
{
InitializeComponent();
komunikat.IsVisible = false;
}
private void funkcja1(object sender, TextChangedEventArgs e)
{
var obiekt = sender as Entry;
// ta wersja jest niebezpieczna bo
// w przypadku tekstu : abc wyrzuci wyjatek lepiej dać
// Try parse
//double wartosc = Convert.ToDouble(obiekt.Text);
if ((double.TryParse(obiekt.Text, out double wartosc)))
{
if ((wartosc >= 0) && (wartosc <= 1))
{
komunikat.IsVisible = false;
}
else
{
obiekt.BackgroundColor = Colors.Yellow;
komunikat.IsVisible = true;
}
}
}
Może Ci się spodobać
MATERIAŁY EDUKACYJNE
18 marca 2020
Kącik dietetyczny
25 listopada 2021