c# - Binding in ControlsTemplate -
i have next control - calendar. got nuget wpcontrols. modified it, because needed button - today.
here xaml code:
<controltemplate x:key="calendarcontroltemplate1" targettype="wpcontrols:calendar"> <scrollviewer> <grid height="auto" background="black"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="*"/> <columndefinition width="auto"/> </grid.columndefinitions> <textblock text="{templatebinding yearmonthlabel}" fontsize="{staticresource phonefontsizemediumlarge}" grid.column="1" horizontalalignment="center" verticalalignment="center"/> <button content="<" width="100" grid.column="0" x:name="previousmonthbutton" horizontalalignment="left" verticalalignment="center" visibility="{binding shownavigationbuttons, converter={staticresource booleantovisibilityconverter}, relativesource={relativesource templatedparent}}"/> <button content=">" width="100" grid.column="2" x:name="nextmonthbutton" horizontalalignment="right" verticalalignment="center" visibility="{binding shownavigationbuttons, converter={staticresource booleantovisibilityconverter}, relativesource={relativesource templatedparent}}"/> <button grid.row="3" grid.column="1" x:name="todaybutton" content="{binding path=buttonname}" horizontalalignment="stretch" height="100" verticalalignment="bottom" tap="button_tap" /> <grid height="auto" grid.row="2" grid.column="0" grid.columnspan="3" x:name="itemsgrid"> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> <columndefinition width="*"/> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> </grid.rowdefinitions> <textblock text="{templatebinding sunday}" horizontalalignment="center" verticalalignment="center" grid.column="1"/> <textblock text="{templatebinding monday}" horizontalalignment="center" verticalalignment="center" grid.column="2"/> <textblock text="{templatebinding tuesday}" horizontalalignment="center" verticalalignment="center" grid.column="3"/> <textblock text="{templatebinding wednesday}" horizontalalignment="center" verticalalignment="center" grid.column="4"/> <textblock text="{templatebinding thursday}" horizontalalignment="center" verticalalignment="center" grid.column="5"/> <textblock text="{templatebinding friday}" horizontalalignment="center" verticalalignment="center" grid.column="6"/> <textblock text="{templatebinding saturday}" horizontalalignment="center" verticalalignment="center" grid.column="7"/> </grid> </grid> </scrollviewer> </controltemplate>
i have added thing:
<button grid.row="3" grid.column="1" x:name="todaybutton" content="{binding path=buttonname}" horizontalalignment="stretch" height="100" verticalalignment="bottom" tap="button_tap" />
i want change it's content, e.g. text when switch languages, have done binding:
content="{binding path=buttonname}"
but doesn't work, why? , how fix it?
here c# code:
string buttonname; public calendarpage() { initializecomponent(); buttonname = gs.translations["today"]; }
as greg said, need have data context implements inotifypropertychange. there's dirty way.hope works. 1) change code this
public string buttonname{get;set;} public calendarpage() { initializecomponent(); buttonname = gs.translations["today"]; }
2) , xaml somthing this
content="{binding elementname=yourusercontrolname,path=buttonname}"
Comments
Post a Comment