button enabling

Eduardo Gomez Romero 825 Reputation points
2024-10-24T16:37:31.56+00:00

I have a pop up

 <DataTemplate>
     <Grid
         Padding="10"
         ColumnDefinitions="*,*"
         RowDefinitions="*,*,*,*"
         RowSpacing="20">

         <Border
             Grid.ColumnSpan="2"
             Style="{x:StaticResource CommonBorderStyle}">
             <Entry
                 Text="{x:Binding Turbine.Name}"
                 TextColor="Black" />
         </Border>

         <Border
             Grid.Row="1"
             Grid.ColumnSpan="2"
             Style="{x:StaticResource CommonBorderStyle}">

             <Grid ColumnDefinitions="*,60">
                 <Entry
                     IsReadOnly="True"
                     Text="{x:Binding Turbine.StringifyInstalationDate}"
                     TextColor="Black" />

                 <Button
                     Grid.Column="1"
                     Command="{Binding OpenDatePickerCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
                     CommandParameter="{x:Binding Source={x:Reference picker}}"
                     FontFamily="ma"
                     FontSize="Large"
                     Text="{x:Static constant:MaterialFonts.Calendar_month}"
                     VerticalOptions="Center" />

             </Grid>
         </Border>

         <picker:SfDateTimePicker
             x:Name="picker"
             Grid.Row="4"
             Style="{x:DynamicResource DateTimePickerStyle}">
             <picker:SfDateTimePicker.Behaviors>

                 <mct:EventToCommandBehavior
                     Command="{Binding BindingContext.CancelDateCommand, Source={x:Reference TurbinesCollection}}"
                     CommandParameter="{x:Binding Source={x:Reference picker}}"
                     EventName="CancelButtonClicked" />

                 <mct:EventToCommandBehavior
                     Command="{Binding BindingContext.ConfirmDateCommand, Source={x:Reference TurbinesCollection}}"
                     CommandParameter="{x:Binding Source={x:Reference picker},
                                                  Path=SelectedDate}"
                     EventName="OkButtonClicked" />

             </picker:SfDateTimePicker.Behaviors>
         </picker:SfDateTimePicker>

         <Border
             Grid.Row="2"
             Grid.ColumnSpan="2"
             Style="{x:StaticResource CommonBorderStyle}">
             <Entry
                 Text="{x:Binding Turbine.Address}"
                 TextColor="Black"
                 VerticalTextAlignment="Center" />
         </Border>

         <Button
             Grid.Row="3"
             Grid.ColumnSpan="2"
             Command="{Binding SaveAndCloseCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
             CommandParameter="{x:Binding Source={x:Reference TurbinePopUp}}"
             CornerRadius="8"
             IsEnabled="{x:Binding IsSaveEnable}"
             VerticalOptions="End" />
     </Grid>

My model

    public partial class Turbine : ObservableObject {
        [ObservableProperty]
        private int id;
        [ObservableProperty]
        private string? name;
        [ObservableProperty]
        private string? address;
        [ObservableProperty]
        private Location? location;
        [ObservableProperty]
        private DateTime? instalationDateTime;
        [ObservableProperty]
        private List<string>? images;
        [ObservableProperty]
        private string? stringifyInstalationDate;
        public string? Label => Name;
    }
}

My VM

  public partial class TurbinesCollectionPageViewModel(TurbinesService turbinesService,
      DeviceLanguageService languageService) :
      ChargingStationsMapPageViewModel(turbinesService) {

      CollectionView? TurbinesCollection;

      [ObservableProperty]
      [NotifyPropertyChangedFor(nameof(IsSaveEnable))]
      private Turbine? turbine = new();

      public bool IsSaveEnable =>
          !string.IsNullOrEmpty(Turbine?.Name) &&
          !string.IsNullOrEmpty(Turbine?.Address);


Because my model is observable, all of my properties should listen every time right?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,588 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,931 Reputation points Microsoft Vendor
    2024-10-25T02:17:19.15+00:00

    Hello,

    Because my model is observable, all of my properties should listen every time right?

    Yes, according to the documentation, properties with the ObservableProperty attribute added can emit notifications when they change.

    You could refer to ObservableProperty attribute for more details about usage of ObservableProperty.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.