imthath
imthath

Reputation: 1708

Xamarin.Forms - Days to Repeat in a week

I want to add something like this to my Xamarin.Forms app, which is generally found in Clock app.

selecting Days of week for repetition

this should help me decide on which days of the week I should repeat certain tasks. Kindly let me know on how to do it with C# and XAML.

Upvotes: 0

Views: 191

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39102

As a quick guide, you would start with the following class:

public class AlarmDay : INotifyPropertyChanged
{
    public AlarmDay( string dayOfWeek )
    {
       DayOfWeek = dayOfWeek;       
    }

    public DayOfWeek { get; }

    private bool _isEnabled = false;
    public bool IsEnabled
    {
        get => _isEnabled;
        set
        {
           _isEnabled = value;
           NotifyPropertyChanged();
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

You could then use a horizontal list control to which you set a ItemsSource with the 7 appropriate instances of AlarmDay class. The DataTemplate could then contain a custom control, that would contain a Label and a Frame with corner-radius outline. You then implement Tap gesture and update the IsEnabled property of the data-bound AlarmDay instance (in BindingContext) and the Frame BackgroundColor.

Upvotes: 2

Related Questions