Nickon
Nickon

Reputation: 10156

Semi-transparent background only in controls

I wonder if it's possible to make a new template (e.g. for a button), that have semi-transparent background? I can set the Background property and then choose my Opacity, but here lies the problem... When I set opacity of the background, each element added as a content of an element with set Opacity will be transparent, too. How to avoid it?

Upvotes: 1

Views: 179

Answers (1)

DHN
DHN

Reputation: 4865

How about this? It's just a simple version. You will have to add the triggers etc by yourself.

<Style x:TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate x:TargetType="Button">
                <Border BorderBrush="{TemplateBinding BorderBrush}">
                    <Grid>
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                        <Border Background="{TemplateBinding Background}"/>
                    </Grid>
                </Border>
            <ControlTemplate/>
        </Setter.Value>
    <Setter/>
</Style>

Now you can assign any background brush you want without influencing the content.

Upvotes: 1

Related Questions