Changing Visual state of an Entry inside a collection view

Manickam, Suraj 320 Reputation points
2023-12-05T14:44:32.97+00:00

I have a Collection view with entries , based on certain conditions , I will have to change the visual state to either disabled or normal . I have already defined them in styles.xaml. I tried it by binding isEnabled property of Entry but the background color of entry does not change according to the ones defined in the Visual state. How do I get this working?

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 71,836 Reputation points Microsoft Vendor
    2023-12-06T07:52:56+00:00

    Do you implement this INotifyPropertyChanged in your Model like following code? After that, your isenabled property will be changed at the runtime.

    public class Monkey: INotifyPropertyChanged
    
    {
         public event PropertyChangedEventHandler PropertyChanged;
         public void OnPropertyChanged([CallerMemberName] string name = "") =>
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
       
         private bool _isEnabled;
         public bool IsEnabled
         {
             get => _isEnabled;
             set
             {
                 if (_isEnabled != value)
                 {
                     _isEnabled = value;
                     OnPropertyChanged(); // reports this property
                 }
             }
         }
    
    
        
    
    }
    
    <Entry 
    
             Text="ddd"
             IsEnabled="{Binding IsEnabled}"
     />
    

0 additional answers

Sort by: Most helpful