Disable DElButton when nothing to delete
This commit is contained in:
25
Jugenddienst Stunden/Converter/IntBoolConverter.cs
Normal file
25
Jugenddienst Stunden/Converter/IntBoolConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jugenddienst_Stunden.Converter;
|
||||
public class IntBoolConverter : IValueConverter {
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
|
||||
if (value is int) {
|
||||
return (int)value != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
|
||||
if (value is bool) {
|
||||
return (bool)value ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
|
||||
xmlns:conv="clr-namespace:Jugenddienst_Stunden.Converter"
|
||||
x:Class="Jugenddienst_Stunden.Views.StundePage"
|
||||
Title="{Binding Title}">
|
||||
|
||||
@@ -9,6 +10,12 @@
|
||||
<models:StundeViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<conv:IntBoolConverter x:Key="IntBoolConverter" />
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<VerticalStackLayout Spacing="10" Margin="10">
|
||||
|
||||
<Label Text="{Binding SubTitle}" />
|
||||
@@ -43,7 +50,7 @@
|
||||
|
||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
||||
<Button Text="Speichern" Command="{Binding SaveCommand}" />
|
||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" />
|
||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" IsEnabled="{Binding Stunde.id, Converter={StaticResource IntBoolConverter}}" />
|
||||
</Grid>
|
||||
|
||||
<BoxView HeightRequest="1" Color="Red" Margin="5,10"/>
|
||||
|
||||
Reference in New Issue
Block a user