Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit is it possible to change style in code behind?
4 replies. Latest Post by xiebin on August 5, 2009.
(0)
xiebin
Member
2 points
10 Posts
07-29-2009 12:42 AM |
Hi Friends,
I have set a style for object in front, and i want to change the textblock.text that is inside the style in code behind as i can bind data into textblock. google seems like not working for me this time, there were very few resources i can refer to. Any suggestion would be appreciated in advance!
Ben
philip.b...
500 points
104 Posts
07-29-2009 1:05 AM |
You can set a style once but you cannot change it once it is set. Im not quite sure what you are asking though.
xiebin: i want to change the textblock.text that is inside the style in code behind as i can bind data into textblock
If you change the text it will automatically have whatever style you already set on the control.
07-29-2009 11:34 PM |
Hi Beadle,
Sorry for the unclear discription of my problem. I have defined a style in front, and i want to create a button in code behind meanwhile set style to the button. is it possible to do that? Thanks
Best Regards,
Ben Xie Bin
Jonathan...
All-Star
24979 points
2,434 Posts
08-04-2009 11:00 PM |
Hi Xiebin,
First, we define the style in app.xaml. For example,
<Style x:Key="ButtonStyle" TargetType="Button">
********
</Style>
Then, call it on code hide when any event is raised. See this.
MyButton.Style = Application.Current.Resources["ButtonStyle"] as Style;
You can get the sample here.
Best regards,
Jonathan
08-05-2009 3:47 AM |
Hi Jonathan,
Thanks for your reply, Your codes is really helpful!
In my case, i used MyButton.Style = (Style)this.Resources["ButtonStyle"];
It comes from your idea.
XieBin