Windows Phone Sets the style for the elements within the specified container

Source: Internet
Author: User

There are several ways to set element styles in Windows Phone
Take TextBlock for a while.
1. We can set it directly on the control:
  < TextBlock   Text = "own style setting"   Width= "  FontSize"= " Foreground"= "#FF6B6A6A"  />
2, you can also do this: in the static resources of the page set
<phone:PhoneApplicationPage.Resources>        <StyleTargetType= "TextBlock"x:name= "Nomalstyle" >            <Setter Property= "Foreground"Value= "#FF6B6A6A" ></Setter>            <Setter Property= "TextTrimming"Value= "WordEllipsis"></Setter>            <Setter Property= "Width"Value= "+"></Setter>            <Setter Property= "FontSize"Value= " the"></Setter>        </Style></phone:PhoneApplicationPage.Resources><!--styling by using the Style property -<TextBlockText= "Set style with style"Style= "{StaticResource Nomalstyle}"  /><!--Styling by using the Style property, adding or modifying styles -<TextBlockText= "Styles are set by style, but fontsize attributes are my own, I have more margin properties than styles"Style= "{StaticResource Nomalstyle}"FontSize= " the"Margin= "12,0" />

3, if you want to set the current page of all TextBlock public style, you can remove the above x:name can be, the page TextBlock will use the style set in the page resources
<phone:PhoneApplicationPage.Resources>        <StyleTargetType= "TextBlock">            <Setter Property= "Foreground"Value= "#FF6B6A6A" ></Setter>            <Setter Property= "TextTrimming"Value= "WordEllipsis"></Setter>            <Setter Property= "Width"Value= "+"></Setter>            <Setter Property= "FontSize"Value= " the"></Setter>        </Style></phone:PhoneApplicationPage.Resources><!--setting styles using page style resources -<TextBlockText= "Use page style resource settings style, I am the same as the text below" /><TextBlockText= "Use page style resource settings style, I am the same as the text above" /><!--use page style resources to set styles, add or modify styles -<TextBlockText= "Use a page style resource to set the style, but I'm not the same as the top, but the FontSize property is my own, and I have more margin properties than the style"FontSize= " the"Margin= "12,0" />

4. If you want to use the entire project, then put the resources described in 2 or 3 in the <Application.Resources> </Application.Resources> node in App.xaml
5, local style how to set it? For example: Setting the style of all the TextBlock in StackPanel, besides setting the style with the above 2 method, what is the method? By Method 2, it can be found that the style is placed in the page resources, then whether the style can be placed in the internal resources of the StackPanel, after implementation is possible
<StackPanel>    <stackpanel.resources>        <StyleTargetType= "TextBlock">            <Setter Property= "Foreground"Value= "#FF6B6A6A" ></Setter>            <Setter Property= "Width"Value= "Panax Notoginseng"></Setter>            <Setter Property= "FontSize"Value= "+"></Setter>            <Setter Property= "Margin"Value= "0"></Setter>            <Setter Property= "TextWrapping"Value= "Wrap"></Setter>            <Setter Property= "TextAlignment"Value= "Center"></Setter>        </Style>    </stackpanel.resources>    <TextBlockText= "I am using a StackPanel internal style, not controlled by a global style resource file" />    <TextBlockText= "I am using a StackPanel internal style, not controlled by a global style resource file" /> </StackPanel>
above is a personal point of view, if there is a problem, please correct me. 

Windows Phone Sets the style for the elements within the specified container

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.