Embedded button in ListBox in Windows Phone 7

Source: Internet
Author: User

In the previous article "use ListBox in Windows Phone 7", I mentioned how to use The ListBox control in Windows Phone 7 and bind data to the control, take a book sales list as an example. Next we will try to update the UI of this example to make the entire interface look a little more beautiful (looking back at the end, it seems not so nice ). Embed a button in ListBox and add the gradient effect to the button.

First, open the project booklist of the previous article, and open the app in the solution window on the right. XAML file (the role of this file is described in the first WP7 project: Hello WP7). We will create a control module in this file. Find the Code:

    <Application.Resources>    </Application.Resources>

Add our control module in the Code. The Code is as follows:

    <Application.Resources>        <Style x:Key="MyButton" TargetType="Button">            <Setter Property="Template">                <Setter.Value>                    <ControlTemplate TargetType="Button">                        <Grid x:Name="RootElement">                            <Rectangle Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" RadiusX="15" RadiusY="15">                                <Rectangle.Fill>                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">                                        <GradientStop Color="Yellow" Offset="0.0" />                                        <GradientStop Color="Red" Offset="0.25" />                                        <GradientStop Color="Blue" Offset="0.75" />                                        <GradientStop Color="LimeGreen" Offset="1.0" />                                    </LinearGradientBrush>                                </Rectangle.Fill>                                <Rectangle.Stroke>                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">                                        <GradientStop Color="#EC04FA" Offset="0" />                                        <GradientStop Color="#FFFFFF" Offset="1" />                                        </LinearGradientBrush>                                </Rectangle.Stroke>                                </Rectangle>                            <ContentPresenter x:Name="contentPresenter" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>                        </Grid>                    </ControlTemplate>                </Setter.Value>            </Setter>        </Style>    </Application.Resources>

After adding the control template, return to our mainpage. XAML.

<DataTemplate>

Add a button control and set the control style as the template style we just compiled. The code after adding the button is as follows:

                    <DataTemplate>                        <Button Width="460" Height="120" Style="{StaticResource MyButton}">                            <Button.Content>                                <StackPanel Orientation="Horizontal">

The concluding remarks are as follows:

                                </StackPanel>                            </Button.Content>                        </Button>                    </DataTemplate>

Press F5 to compile, and the final result is as follows:

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.