xaml - How to change TextBox placeholder text color for a specific element, not global -
msdn lists styles , templates textbox class here. can override these theme resources creating resourcedictionary in app.xaml this:
<application.resources> <resourcedictionary> <resourcedictionary.themedictionaries> <resourcedictionary x:key="default"> <solidcolorbrush x:key="textboxplaceholdertextthemebrush" color="yellow"/> </resourcedictionary> </resourcedictionary.themedictionaries> </resourcedictionary> </application.resources> but impact every textbox in app. how can set theme specific element?
i've tried putting dictionary in page.resources , textbox.resources textbox want apply to, doesn't work.
i really don't want have redefine template alter property.
edit heena's reply close, set different colors lite , dark themes because textbox has transparent background color.
i managed accomplish keeping foreground="{themeresource textboxplaceholdertextthemebrush}" part of template (so, in other words, template default per msdn) , specifying in page resources:
<page.resources> <resourcedictionary.themedictionaries> <resourcedictionary x:key="light"> <solidcolorbrush x:key="textboxplaceholdertextthemebrush" color="blue"/> </resourcedictionary> ... </resourcedictionary.themedictionaries> </page.resources> but means have set huge controltemplate style-setter textbox in page resources too, exact duplicate of default anyway!
does have how textboxplaceholdertextthemebrush resolved within controltemplate? i.e. reason why discovers custom theme dictionary because controltemplate defined in same resource dictionary?
how supposed done? should subclass textbox xaml can moved file (even if 1 textbox)?
assuming using msdn textbox style
resource remove foreground property contencontrol in template<contentcontrol foreground="{themeresource textboxplaceholdertextthemebrush}"/>
<page.resources> <!--from msdn : default style windows.ui.xaml.controls.textbox --> <style x:key="msdntextboxstyle" targettype="textbox"> <setter property="template"> <setter.value> <controltemplate targettype="textbox"> ..... ..... <contentcontrol x:name="placeholdertextcontentpresenter" grid.row="1" margin="{templatebinding borderthickness}" padding="{templatebinding padding}" istabstop="false" grid.columnspan="2" content="{templatebinding placeholdertext}" ishittestvisible="false"/> </controltemplate> </setter.value> </setter> </style> </page.resources> xaml
<stackpanel orientation="horizontal"> <textbox placeholdertext="placeholdertext here..." style="{staticresource msdntextboxstyle}" margin="20" foreground="red" height="30" width="120"> <textbox.resources> <style targettype="contentcontrol"> <setter property="foreground" value="green"/> </style> </textbox.resources> </textbox> <textbox placeholdertext="placeholdertext here..." style="{staticresource msdntextboxstyle}" margin="20" foreground="red" height="30" width="120"> <textbox.resources> <style targettype="contentcontrol"> <setter property="foreground" value="red"/> </style> </textbox.resources> </textbox> <textbox placeholdertext="placeholdertext here..." style="{staticresource msdntextboxstyle}" margin="20" foreground="red" height="30" width="120"> <textbox.resources> <style targettype="contentcontrol"> <setter property="foreground" value="blue"/> </style> </textbox.resources> </textbox> </stackpanel> update
resource
remove foreground property contencontrol in template<contentcontrol foreground="{themeresource textboxplaceholdertextthemebrush}"/>
<page.resources> <resourcedictionary> <resourcedictionary.themedictionaries> <resourcedictionary x:key="default"> <solidcolorbrush x:key="contentcontrolforeground" color="red"></solidcolorbrush> <solidcolorbrush x:key="contentcontrolforeground1" color="yellow"></solidcolorbrush> </resourcedictionary> <resourcedictionary x:key="light"> <solidcolorbrush x:key="contentcontrolforeground" color="blue"></solidcolorbrush> <solidcolorbrush x:key="contentcontrolforeground1" color="skyblue"></solidcolorbrush> </resourcedictionary> <resourcedictionary x:key="dark"> <solidcolorbrush x:key="contentcontrolforeground" color="green"></solidcolorbrush> <solidcolorbrush x:key="contentcontrolforeground1" color="chocolate"></solidcolorbrush> </resourcedictionary> </resourcedictionary.themedictionaries> <style x:key="textboxstyle1" targettype="textbox"> ..... <contentcontrol x:name="placeholdertextcontentpresenter" grid.columnspan="2" content="{templatebinding placeholdertext}" ishittestvisible="false" istabstop="false" margin="{templatebinding borderthickness}" padding="{templatebinding padding}" grid.row="1"/> ...... </style> </resourcedictionary> </page.resources> xaml
<stackpanel orientation="horizontal"> <textbox style="{staticresource textboxstyle1}" placeholdertext="placeholdertext here..." margin="20" foreground="red" height="30" width="170"> <textbox.resources> <style targettype="contentcontrol"> <setter property="foreground" value="{staticresource contentcontrolforeground}"></setter> </style> </textbox.resources> </textbox> <textbox style="{staticresource textboxstyle1}" placeholdertext="placeholdertext here..." margin="20" foreground="red" height="30" width="170"> <textbox.resources> <style targettype="contentcontrol"> <setter property="foreground" value="{staticresource contentcontrolforeground1}"></setter> </style> </textbox.resources> </textbox> </stackpanel> xaml windows-runtime windows-store-apps windows-8.1
No comments:
Post a Comment