c# - Silverlight/WPF Calendar how to get visible dates -
i want visible dates in calendar, example following image want june 28th of 2015 august 8th of 2015
all in event displaydatechanged
addeddate = {01/07/2015 00:00:00} (july 1st)
removeddate = {25/06/2015 00:00:00} (june 25th)
at first thought displaydatestart , displaydateend give me information, realized these properties not readonly, instead set them other purposes such date range displayed.
so workaround or way calculate or result want?
i got answer through questions , doing changes in calendar template.
i clicked edit additional templates/edit calendardaybuttonstyle, added following:
<setter property="tag" value="{binding path=date}" /> private void mycal_displaydatechanged(object sender, calendardatechangedeventargs e) { var grid = findvisualchildbyname<grid>(mycal, "monthview"); datetime? dtbegin = null; datetime? dtend = null; if (grid != null && grid.children.oftype<system.windows.controls.primitives.calendardaybutton>().any()) { foreach (var button in grid.children.oftype<system.windows.controls.primitives.calendardaybutton>().cast<system.windows.controls.primitives.calendardaybutton>()) { if (dtbegin == null) dtbegin = convert.todatetime(button.tag); else dtend = convert.todatetime(button.tag); } } } public static t findvisualchildbyname<t>(dependencyobject parent, string name) t : dependencyobject { (int = 0; < visualtreehelper.getchildrencount(parent); i++) { var child = visualtreehelper.getchild(parent, i); string controlname = child.getvalue(control.nameproperty) string; if (controlname == name) { return child t; } else { t result = findvisualchildbyname<t>(child, name); if (result != null) return result; } } return null; }
detecting when day clicked on silverlight calendar control
https://pwnedcode.wordpress.com/2009/04/01/find-a-control-in-a-wpfsilverlight-visual-tree-by-name/
Comments
Post a Comment