Add a style to the Windows Phone 7 CS page

Source: Internet
Author: User

Controls are generally assigned a value on the XAML page. However, in some special environments, such as dynamically generating controls, you need to add styles to the controls on the CS page.

Method 1:

Add the style as a global resource on the app. XAML page.

<Application. Resources>
......
</Application. Resources>

Then, the other CS pages go through the followingCodeTo assign a style

Style mystyle = application. Current. Resources [stylename] as style;

Button bt = new button ();

Bt. Style = mystyle;

 

Method 2:

Write style code directly on the CS page

For example:

VaR style = new style ();
Style. setters. Add (New setter (backgroundproperty, new solidcolorbrush (colors. Red )));
Style. setters. Add (New setter (foregroundproperty, new solidcolorbrush (colors. Blue )));
VaR stylecopy = new style ();

foreach (VAR Setter in style. setters)
{< br> var typedsetter = setter as setter;
If (typedsetter! = NULL)
{< br> var newsetter = new setter (typedsetter. property, typedsetter. value);
stylecopy. setters. add (newsetter);
}< BR >}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.