Is it possible to disable certain days from the FMX TCalendar component?
e.g. Weekends
It would also be good if they could be highlited that they are disabled e.g. days 14 and 15 in the image below
I can kind of get it disabled by adding a rectangle onto a listboxitemstyle with the hit test turned on
This is what i did for the image above
procedure TForm1.cal1DayClick(Sender: TObject);
var sTemp : String;
begin
cal1.StylesData['days.Selected.StyleLookup'] := 'ListBoxItemstyleCust';
end;
but i don't know how to access the styleslistbox items on the creation of the item and even if this is the way i should be doing it
After some time digging around this is a quick explanation of what i found Source code here
In the folder \Embarcadero\Studio\17.0\source\fmx There is a FMX.Calendar.Style.pas file
I have copied that file into the same location as my project and renamed it to My.FMX.Calendar.Style.pas
I have also renamed TStyledCalendar to TMyStyledCalendar, then changed the initialization and finalization from
initialization
TPresentationProxyFactory.Current.Register(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
finalization
TPresentationProxyFactory.Current.Unregister(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
end.
initialization
TPresentationProxyFactory.Current.Unregister(TCalendar, TControlType.Styled, TStyledPresentationProxy<TStyledCalendar>);
TPresentationProxyFactory.Current.Register(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
finalization
TPresentationProxyFactory.Current.Unregister(TCalendar, TControlType.Styled, TStyledPresentationProxy<TMyStyledCalendar>);
also added FMX.Calendar.Style into the uses section
in the procedure FillDays; created a new procedure
procedure ChangeStyle(aDay : TDateTime;Item: TDayItem);
var wDay : Word;
begin
wDay := DayOfWeek(aDay-1);
if (wDay = DaySaturday) or (wday = DaySunday) then begin
item.Enabled := false;
if (Item.StyleLookup <> 'MyListBoxItemstyle') then
Item.StyleLookup := 'MyListBoxItemstyle';
end else begin
if (Item.StyleLookup <> '') then
Item.StyleLookup := '';
end;
end;
and added the ChangeStyle( Item.Date, Item); to the following FillDaysOfPreviousMonth; FillDaysOfCurrentMonth; FillDaysOfNextMonth;
added a Styles to match MyListBoxItemstyle
after playing with the styles got it to look something like this