2015-11-18 65 views
0

是否可以從FMX TCalendar組件禁用某些日期? 例如週末
如果他們可能被強迫停用,例如下面Delphi FMX TCalendar - 禁用週末

enter image description here

我可以種得到它禁用圖像天14和15通過添加矩形到listboxitemstyle與命中測試開啓
這就是我做了以上的圖像

procedure TForm1.cal1DayClick(Sender: TObject); 
var sTemp : String; 
begin 
    cal1.StylesData['days.Selected.StyleLookup'] := 'ListBoxItemstyleCust'; 
end; 

,但我不知道如何訪問對創建項目的styleslistbox項目,即使是這樣的方式,我應該做它

回答

1

一些TI之後我周圍挖這個是我發現了什麼 Source code here

在文件夾 \ Embarcadero公司\工作室\ 17.0 \源\ FMX 一個快速的解釋有一種FMX.Calendar.Style.pas文件

我有複製該文件到同一位置作爲我的項目,並將其更名爲My.FMX.Calendar.Style.pas

我也改名TStyledCalendar到TMyStyledCalendar,然後改變了初始化和結束從

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>); 

還在程序FillDays中將FMX.Calendar.Style添加到使用部分
中;創建了一個新程序

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; 

並添加了ChangeStyle(Item.Date,Item);到以下FillDaysOfPreviousMonth; FillDaysOfCurrentMonth; FillDaysOfNextMonth;

增加了一個樣式與風格的播放後,以匹配MyListBoxItemstyle

Styled Calendar

得到它看起來像這樣 Styled Calendar v2