Ejemplo n.º 1
0
        protected override ConversionResult <DayOfWeeksFlags> Convert(IEnumerable <DayOfWeek> value, Type targetType, object parameter, CultureInfo culture)
        {
            DayOfWeeksFlags dayOfWeekFlags = DayOfWeeksFlags.None;

            if (value == null)
            {
                return(ConversionResult <DayOfWeeksFlags> .SetValue(dayOfWeekFlags));
            }

            foreach (var dayOfWeek in value)
            {
                switch (dayOfWeek)
                {
                case DayOfWeek.Monday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Monday;
                    break;

                case DayOfWeek.Thursday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Thursday;
                    break;

                case DayOfWeek.Tuesday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Tuesday;
                    break;

                case DayOfWeek.Wednesday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Wednesday;
                    break;

                case DayOfWeek.Friday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Friday;
                    break;

                case DayOfWeek.Sunday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Sunday;
                    break;

                case DayOfWeek.Saturday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Saturday;
                    break;
                }
            }

            return(ConversionResult <DayOfWeeksFlags> .SetValue(dayOfWeekFlags));
        }
Ejemplo n.º 2
0
        protected override ConversionResult <IEnumerable <DayOfWeek> > ConvertBack(DayOfWeeksFlags value, Type targetType, object parameter, CultureInfo culture)
        {
            var list = new List <DayOfWeek>();

            if (value.HasFlag(DayOfWeeksFlags.Monday))
            {
                list.Add(DayOfWeek.Monday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Tuesday))
            {
                list.Add(DayOfWeek.Tuesday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Wednesday))
            {
                list.Add(DayOfWeek.Wednesday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Thursday))
            {
                list.Add(DayOfWeek.Thursday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Friday))
            {
                list.Add(DayOfWeek.Friday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Saturday))
            {
                list.Add(DayOfWeek.Saturday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Sunday))
            {
                list.Add(DayOfWeek.Sunday);
            }

            return(ConversionResult <IEnumerable <DayOfWeek> > .SetValue(list));
        }
Ejemplo n.º 3
0
        public static TargetItemBinding <WeekDayFragmentViewHolder, DayOfWeeksFlags> WeekdayCheckedAndCheckedChangedBinding(
            [NotNull] this IItemReference <WeekDayFragmentViewHolder> weekDayFragemntReference,
            bool trackCanExecuteCommandChanged = false)
        {
            if (weekDayFragemntReference == null)
            {
                throw new ArgumentNullException(nameof(weekDayFragemntReference));
            }

            return(new TargetItemTwoWayCustomBinding <WeekDayFragmentViewHolder, DayOfWeeksFlags, CompoundButton.CheckedChangeEventArgs>(
                       weekDayFragemntReference,
                       (holder, handler) =>
            {
                holder.Monday.CheckedChange += handler;
                holder.Tuesday.CheckedChange += handler;
                holder.Wednesday.CheckedChange += handler;
                holder.Thursday.CheckedChange += handler;
                holder.Friday.CheckedChange += handler;
                holder.Suturday.CheckedChange += handler;
                holder.Sunday.CheckedChange += handler;
            },
                       (holder, handler) =>
            {
                holder.Monday.CheckedChange -= handler;
                holder.Tuesday.CheckedChange -= handler;
                holder.Wednesday.CheckedChange -= handler;
                holder.Thursday.CheckedChange -= handler;
                holder.Friday.CheckedChange -= handler;
                holder.Suturday.CheckedChange -= handler;
                holder.Sunday.CheckedChange -= handler;
            },
                       (holder, canExecuteCommand) =>
            {
                if (trackCanExecuteCommandChanged)
                {
                    holder.Monday.Enabled = canExecuteCommand;
                    holder.Tuesday.Enabled = canExecuteCommand;
                    holder.Wednesday.Enabled = canExecuteCommand;
                    holder.Thursday.Enabled = canExecuteCommand;
                    holder.Friday.Enabled = canExecuteCommand;
                    holder.Suturday.Enabled = canExecuteCommand;
                    holder.Sunday.Enabled = canExecuteCommand;
                }
            },
                       (holder, args) =>
            {
                DayOfWeeksFlags weeks = DayOfWeeksFlags.None;

                if (holder.Monday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Monday;
                }

                if (holder.Tuesday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Tuesday;
                }

                if (holder.Wednesday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Wednesday;
                }

                if (holder.Thursday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Thursday;
                }

                if (holder.Friday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Friday;
                }

                if (holder.Suturday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Saturday;
                }

                if (holder.Sunday.Checked)
                {
                    weeks = weeks | DayOfWeeksFlags.Sunday;
                }

                return weeks;
            },
                       (holder, weeks) =>
            {
                holder.Monday.Checked = false;
                holder.Tuesday.Checked = false;
                holder.Wednesday.Checked = false;
                holder.Thursday.Checked = false;
                holder.Friday.Checked = false;
                holder.Suturday.Checked = false;
                holder.Sunday.Checked = false;

                if (weeks.HasFlag(DayOfWeeksFlags.Monday))
                {
                    holder.Monday.Checked = true;
                }

                if (weeks.HasFlag(DayOfWeeksFlags.Tuesday))
                {
                    holder.Tuesday.Checked = true;
                }

                if (weeks.HasFlag(DayOfWeeksFlags.Wednesday))
                {
                    holder.Wednesday.Checked = true;
                }

                if (weeks.HasFlag(DayOfWeeksFlags.Thursday))
                {
                    holder.Thursday.Checked = true;
                }

                if (weeks.HasFlag(DayOfWeeksFlags.Friday))
                {
                    holder.Friday.Checked = true;
                }

                if (weeks.HasFlag(DayOfWeeksFlags.Saturday))
                {
                    holder.Suturday.Checked = true;
                }

                if (weeks.HasFlag(DayOfWeeksFlags.Sunday))
                {
                    holder.Sunday.Checked = true;
                }
            },
                       () => "CheckedChanged"));
        }