Windows phone8.1 Styles

Source: Internet
Author: User

Just like using CSS in HTML, applying a style to a XAML element can beautify the interface.

Create a style inside a control resource property

<StackPanel> <StackPanel.Resources> <style x:key="Commonstyle"Targettype="Button"> <setter property="Width"Value=" $"></Setter> <setter property="Height"Value=" the"></Setter> <setter property="FontSize"Value=" -"></Setter> <setter property="Foreground"Value="Red"></Setter> <setter property="FontFamily"Value="Arial"></Setter> </Style> </StackPanel.Resources> <button style="{StaticResource Commonstyle}"> Local Styles </Button> </StackPanel>

Styles created in resource can only be localized, as the above style can only be used within the StackPanel range. Sometimes the style we want to create is available throughout the page, so we create a style under the page node

<Page.Resources> <style targettype="Button"x:key="Pagestyle"> <setter property="Width"Value=" $"></Setter> <setter property="Height"Value=" -"> </Setter> <setter property="Foreground"Value="Green"></Setter> </Style> </Page.Resources>

When it comes to the application, we cannot have an interface, and when multiple pages have a common style, we need to create a style that allows each interface to be used instead of CTRL + C and CTRL + V. Styles created in the App.xaml file can be used throughout the application

<Application.Resources> <style targettype="Button"x:key="Outstyle"> <setter property="Width"Value=" $"></Setter> <setter property="Height"Value=" the"></Setter> <setter property="FontSize"Value=" -"></Setter> <setter property="Foreground"Value="Blue"></Setter> <setter property="FontFamily"Value="Arial"></Setter> </Style> </Application.Resources>

If the program is larger, the interface is more than we use the above method to create a style, we will use the program is difficult to maintain, this is we need to create a style file, as in the use of CSS, CSS style is placed in a separate file. Add a buttonstyle.xaml style file to your program

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="Using:apptheme"> <style x:key="Style1"Targettype="Button"> <setter property="Width"Value=" -"></Setter> <setter property="Height"Value=" -"></Setter> <setter property="Foreground"Value="Burlywood"></Setter> </Style></ResourceDictionary>

After the style file is created, we just need to use it in reference, we can refer to it in the App.xaml file, or reference it in the normal page, the App.xaml reference is global, the normal page reference can only be used for the current page, the reference is as follows

Referencing in App.xaml

<Application.Resources>        <ResourceDictionary>            <ResourceDictionary.MergedDictionaries>                <resourcedictionary source="buttonstyle.xaml"></ResourceDictionary>            </ResourceDictionary.MergedDictionaries>        </ResourceDictionary>            </ Application.resources>

In the page reference

<Page.Resources>                <ResourceDictionary>            <ResourceDictionary.MergedDictionaries>                <resourcedictionary source="buttonstyle.xaml"/>            </ resourcedictionary.mergeddictionaries>        </ResourceDictionary>    </Page.Resources>

Styles in Windows Phone support inheritance, which makes it more flexible to use styles and also reduces code redundancy.

<style targettype="Button"x:key="Pagestyle"> <setter property="Width"Value=" $"></Setter> <setter property="Height"Value=" -"> </Setter> <setter property="Foreground"Value="Green"></Setter> </Style> <!--style Inheritance--<style targettype="TextBlock"basedon="{StaticResource Pagestyle}"x:key="Textblockstyle"> <setter property="textwrapping"Value="Wrap"></Setter> </Style>

Windows phone8.1 Styles

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.