XamForms.Controls.Calendar icon indicating copy to clipboard operation
XamForms.Controls.Calendar copied to clipboard

Paterns on special dates and special date Selection

Open ambsenyestudi opened this issue 7 years ago • 4 comments

Hello, great control. I have an scenario on which there is only one month, but I need patterns on my special dates. When selecting a special date that has a list of patterns as BackgroundPattern, some times said selected special date turns its background to white, loosing the pattern. I wasn't capable of pin pointing the exact ocurrance, It's a bit random. How can I fix it?

ambsenyestudi avatar Jun 25 '18 10:06 ambsenyestudi

Hello. I've noticed the same behaviour (only tested on Android). It looks like the selected date background color overrides the backgroundPattern. I've tried setting the SelectedBackgroundColor to Default or Transparent but it still overrides the backgroundPattern of the selected date.

By looking the code a bit it looks like (i think) the BackgroundPattern is being overridden by the default background color when a user selects a date. https://github.com/rebeccaXam/XamForms.Controls.Calendar/blob/9dacada447d08be6ced34041f6e5570ff33a95eb/XamForms.Controls.Calendar/Calendar.Selected.cs#L242

pantelisGeo90 avatar Sep 10 '19 10:09 pantelisGeo90

Hello.

I have the same problem.

Any solution?

FranRDev avatar Sep 20 '19 05:09 FranRDev

I fixed it moving the assignment of BackgroundPattern at the end.

protected void SetButtonSelected(CalendarButton button, SpecialDate special) {
    Device.BeginInvokeOnMainThread(() => {
        button.BackgroundImage = special != null ? special.BackgroundImage : null;
        var defaultBackgroundColor = button.IsOutOfMonth ? DatesBackgroundColorOutsideMonth : DatesBackgroundColor;
        var defaultTextColor = button.IsOutOfMonth ? DatesTextColorOutsideMonth : DatesTextColor;
        var defaultFontAttributes = button.IsOutOfMonth ? DatesFontAttributesOutsideMonth : DatesFontAttributes;
        var defaultFontFamily = button.IsOutOfMonth ? DatesFontFamilyOutsideMonth : DatesFontFamily;
        button.IsEnabled = true;
        button.IsSelected = true;
        button.FontSize = SelectedFontSize;
        button.BorderWidth = SelectedBorderWidth;
        button.BorderColor = SelectedBorderColor;
        button.BackgroundColor = SelectedBackgroundColor != Color.Default ? SelectedBackgroundColor : (special != null && special.BackgroundColor.HasValue ? special.BackgroundColor.Value : defaultBackgroundColor);
        button.TextColor = SelectedTextColor != Color.Default ? SelectedTextColor : (special != null && special.TextColor.HasValue ? special.TextColor.Value : defaultTextColor);
        button.FontAttributes = SelectedFontAttributes != FontAttributes.None ? SelectedFontAttributes : (special != null && special.FontAttributes.HasValue ? special.FontAttributes.Value : defaultFontAttributes);
        button.FontFamily = !string.IsNullOrEmpty(SelectedFontFamily) ? SelectedFontFamily : (special != null && !string.IsNullOrEmpty(special.FontFamily) ? special.FontFamily : defaultFontFamily);
        button.BackgroundPattern = special != null ? special.BackgroundPattern : null;
    });
}

FranRDev avatar Oct 01 '19 09:10 FranRDev

@KerosenoDev can you make a pull request to this repository so we can get it fixed?

lubiepomaranczki avatar Oct 01 '19 09:10 lubiepomaranczki