c# - Select Multiple Dates in one calendar control with different SelectedBackgroundColor -
i want make calendar this:
the main idea select diferent days each day color selected in radiobutton. radiobuttons piece of code done , works fine but, have not idea how select days in 1 color, because multiplerange select mode, each time clear days selected...
i'm working styles complicated... style calendard
<style x:key="calendarstyle" targettype="{x:type calendar}"> <setter property="foreground" value="{dynamicresource itemtext}"/> <setter property="background" value="transparent"/> <setter property="borderbrush" value="{dynamicresource itemborder}"/> <setter property="borderthickness" value="1"/> <!--<setter property="calendarbuttonstyle" value="{dynamicresource {x:type calendarbutton}}"/>--> <!--<setter property="calendardaybuttonstyle" value="{dynamicresource {x:type calendardaybutton}}"/>--> <setter property="calendardaybuttonstyle" value="{dynamicresource calendardaybuttonstyleoriginal}" /> <setter property="calendaritemstyle" value="{dynamicresource calendaritemstyle}"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type calendar}"> <stackpanel x:name="part_root" horizontalalignment="center"> <calendaritem x:name="part_calendaritem" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" style="{templatebinding calendaritemstyle}"/> </stackpanel> </controltemplate> </setter.value> </setter> </style> <style x:key="calendaritemstyle" targettype="{x:type calendaritem}"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type calendaritem}"> <controltemplate.resources> <datatemplate x:key="{componentresourcekey resourceid=daytitletemplate, typeintargetassembly={x:type calendaritem}}"> <textblock x:name="text" foreground="{dynamicresource itemtext}" fontweight="bold" fontsize="{dynamicresource defaultfontsize}" horizontalalignment="center" margin="0,6" text="{binding}" verticalalignment="center"/> </datatemplate> </controltemplate.resources> <grid x:name="part_root"> <border borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}"> <grid> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition minwidth="132" width="*"/> <columndefinition width="auto"/> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="*"/> </grid.rowdefinitions> <button x:name="part_headerbutton" grid.column="1" fontweight="bold" ishittestvisible="false" focusable="false" horizontalalignment="stretch" margin="-1,-1,-1,0" grid.row="0" verticalalignment="center"/> <grid x:name="part_monthview" grid.columnspan="3" horizontalalignment="center" margin="8" grid.row="1" visibility="visible"> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> <columndefinition width="auto"/> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> </grid.rowdefinitions> </grid> </grid> </border> </grid> </controltemplate> </setter.value> </setter> </style>
this style calendardaybutton
<style targettype="calendardaybutton" x:key="calendardaybuttonstyleoriginal"> <setter property="minwidth" value="5" /> <setter property="minheight" value="5" /> <setter property="fontsize" value="15" /> <setter property="horizontalcontentalignment" value="center" /> <setter property="verticalcontentalignment" value="center" /> <setter property="template"> <setter.value> <controltemplate targettype="calendardaybutton"> <grid> <visualstatemanager.visualstategroups> <visualstategroup name="commonstates"> <visualstategroup.transitions> <visualtransition generatedduration="0:0:0.1" /> </visualstategroup.transitions> <visualstate name="normal" /> <visualstate name="mouseover"> <storyboard> <doubleanimation storyboard.targetname="highlightbackground" storyboard.targetproperty="opacity" to="0.5" duration="0" /> </storyboard> </visualstate> <visualstate name="pressed"> <storyboard> <doubleanimation storyboard.targetname="highlightbackground" storyboard.targetproperty="opacity" to="0.5" duration="0" /> </storyboard> </visualstate> <visualstate name="disabled"> <storyboard> <doubleanimation storyboard.targetname="highlightbackground" storyboard.targetproperty="opacity" to="0" duration="0" /> <doubleanimation storyboard.targetname="normaltext" storyboard.targetproperty="opacity" to=".35" duration="0" /> </storyboard> </visualstate> </visualstategroup> <visualstategroup name="selectionstates"> <visualstategroup.transitions> <visualtransition generatedduration="0" /> </visualstategroup.transitions> <visualstate name="unselected" /> <visualstate name="selected"> <storyboard> <doubleanimation storyboard.targetname="selectedbackground" storyboard.targetproperty="opacity" to=".75" duration="0" /> </storyboard> </visualstate> </visualstategroup> <visualstategroup name="calendarbuttonfocusstates"> <visualstategroup.transitions> <visualtransition generatedduration="0" /> </visualstategroup.transitions> <visualstate name="calendarbuttonfocused"> <storyboard> <objectanimationusingkeyframes storyboard.targetname="daybuttonfocusvisual" storyboard.targetproperty="visibility" duration="0"> <discreteobjectkeyframe keytime="0"> <discreteobjectkeyframe.value> <visibility>visible</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> </objectanimationusingkeyframes> </storyboard> </visualstate> <visualstate name="calendarbuttonunfocused"> <storyboard> <objectanimationusingkeyframes storyboard.targetname="daybuttonfocusvisual" storyboard.targetproperty="visibility" duration="0"> <discreteobjectkeyframe keytime="0"> <discreteobjectkeyframe.value> <visibility>collapsed</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> </objectanimationusingkeyframes> </storyboard> </visualstate> </visualstategroup> <visualstategroup name="activestates"> <visualstategroup.transitions> <visualtransition generatedduration="0" /> </visualstategroup.transitions> <visualstate name="active" /> <visualstate name="inactive"> <storyboard> <coloranimation duration="0" storyboard.targetname="normaltext" storyboard.targetproperty="(textelement.foreground). (solidcolorbrush.color)" to="#ff777777" /> </storyboard> </visualstate> </visualstategroup> <visualstategroup name="daystates"> <visualstategroup.transitions> <visualtransition generatedduration="0" /> </visualstategroup.transitions> <visualstate name="regularday" /> <visualstate name="today"> <storyboard> <doubleanimation storyboard.targetname="todaybackground" storyboard.targetproperty="opacity" to="1" duration="0" /> <coloranimation duration="0" storyboard.targetname="normaltext" storyboard.targetproperty="(textelement.foreground). (solidcolorbrush.color)" to="#ffffffff" /> </storyboard> </visualstate> </visualstategroup> <visualstategroup name="blackoutdaystates"> <visualstategroup.transitions> <visualtransition generatedduration="0" /> </visualstategroup.transitions> <visualstate name="normalday" /> <visualstate name="blackoutday"> <storyboard> <doubleanimation duration="0" storyboard.targetname="blackout" storyboard.targetproperty="opacity" to=".2" /> </storyboard> </visualstate> </visualstategroup> </visualstatemanager.visualstategroups> <rectangle x:name="todaybackground" radiusx="1" radiusy="1" opacity="0"> <rectangle.fill> <solidcolorbrush color="{dynamicresource selectedbackgroundcolor}" /> </rectangle.fill> </rectangle> <rectangle x:name="selectedbackground" radiusx="1" radiusy="1" opacity="0"> <rectangle.fill> <solidcolorbrush color="{dynamicresource selectedbackgroundcolor}" /> </rectangle.fill> </rectangle> <border background="{templatebinding background}" borderthickness="{templatebinding borderthickness}" borderbrush="{templatebinding borderbrush}" /> <rectangle x:name="highlightbackground" radiusx="1" radiusy="1" opacity="0"> <rectangle.fill> <solidcolorbrush color="{dynamicresource controlmouseovercolor}" /> </rectangle.fill> </rectangle> <contentpresenter x:name="normaltext" horizontalalignment="{templatebinding horizontalcontentalignment}" verticalalignment="{templatebinding verticalcontentalignment}" margin="5,1,5,1"> <textelement.foreground> <solidcolorbrush color="#ff333333" /> </textelement.foreground> </contentpresenter> <path x:name="blackout" opacity="0" margin="3" horizontalalignment="stretch" verticalalignment="stretch" rendertransformorigin="0.5,0.5" fill="#ff000000" stretch="fill" data="m8.1772461,11.029181 l10.433105, 11.029181 l11.700684,12.801641 l12.973633, 11.029181 l15.191895,11.029181 l12.844727, 13.999395 l15.21875,17.060919 l12.962891, 17.060919 l11.673828,15.256231 l10.352539, 17.060919 l8.1396484,17.060919 l10.519043, 14.042364 z" /> <rectangle x:name="daybuttonfocusvisual" visibility="collapsed" ishittestvisible="false" radiusx="1" radiusy="1"> <rectangle.stroke> <solidcolorbrush color="{dynamicresource selectedbackgroundcolor}" /> </rectangle.stroke> </rectangle> </grid> </controltemplate> </setter.value> </setter> </style>
and dynamicresources background
<color x:key="selectedbackgroundcolor">crimson</color> <color x:key="selectedunfocusedcolor">#ffdddddd</color>
this codebehind:
cal = new calendar(); cal.name = "monthlycalendar"; cal.displaymode = calendarmode.month; cal.selectionmode = calendarselectionmode.multiplerange; cal.style = (style)app.current.resources["calendarstyle"];
any help??
Comments
Post a Comment