michielpost.nl

Silverlight Styling

10-10-2008

Silverlight has a powerful model to customize the look and feel of controls.

 

For example, you can alter the looks of a Button control by not supplying just a text for its content property, but an elipse with text in it. That way, the button will not be rendered as a default button, but use your own supplied style.

 

To be able to easily reuse your custom template, you can define a style in the App.xaml and manually set the style property on the button control. This works similar like CSS.

 

Example template to show the content of a button as an image (App.xaml):

<Style x:Key="ImageButtonStyle" TargetType="Button">

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="Button">

                        <Grid>

                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center">

                                <ContentPresenter.Content>

                                    <Image Source="{TemplateBinding Content}"></Image>

                                </ContentPresenter.Content>

                            </ContentPresenter>

                        </Grid>

                    </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style>

 You can set the style on your button this way:
<Button Style="{StaticResource ImageButtonStyle}" Content="Img.png">

 

Comments


God, I feel like I sholud be takin notes! Great work 29-11-2015
God, I feel like I sholud be takin notes! Great work


That's a cunning answer to a chigaenllng question http://reoyyoutany.com [url=http://ezmsmjbgfxr.com]ezmsmjbgfxr[/url] [link=http://lnzcntpt.com]lnzcntpt[/link] 01-12-2015
That's a cunning answer to a chigaenllng question http://reoyyoutany.com [url=http://ezmsmjbgfxr.com]ezmsmjbgfxr[/url] [link=http://lnzcntpt.com]lnzcntpt[/link]


I love reading these articles because they're short but <a href="http://yulhoevpo.com">intormafive.</a> 03-12-2015
I love reading these articles because they're short but <a href="http://yulhoevpo.com">intormafive.</a>


It's a joy to find sooemne who can think like that http://gfupmrb.com [url=http://pdmqopz.com]pdmqopz[/url] [link=http://jassztly.com]jassztly[/link] 04-12-2015
It's a joy to find sooemne who can think like that http://gfupmrb.com [url=http://pdmqopz.com]pdmqopz[/url] [link=http://jassztly.com]jassztly[/link]


New Comment

Name
E-mail (not published)
Comment
Enter the code shown: