Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:42:00+00:00 2026-05-26T23:42:00+00:00

I have a WPF button style below: <Style x:Key=myButtonStyle TargetType={x:Type Button}> <Setter Property=Template> <Setter.Value>

  • 0

I have a WPF button style below:

<Style x:Key="myButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid Width="{Binding Width}" Height="{Binding Height}">
                    <Border Name="container" Background="{Binding Background}" CornerRadius="{Binding CornerRadius}">
                        <TextBlock Margin="10" FontFamily="Arial" FontWeight="Bold" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" FontSize="{Binding TextSize}" Foreground="White" Text="{Binding Text}" TextWrapping="Wrap"/>
                    </Border>
                    <Border Name="overlay" Background="Transparent" CornerRadius="{Binding CornerRadius}" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="overlay" Property="Opacity" Value="0.6" />
                        <Setter TargetName="overlay" Property="Background" Value="Black" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The problem is that, although all of the buttons of my application have the same style, some of them need to have a border around it. Therefore I would like to know if it is possible to access the container border of my style to set its thickness and color? If so how can I do this?

Edit:

I’ve mixed the suggestions of madd0 and Josh and created a DataTrigger inside my style with a binding to a property that tells me if the button should or should not have a border.

The final code is below:

<Style x:Key="myButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid Width="{Binding Width}" Height="{Binding Height}">
                    <Border Name="container" Background="{Binding Background}" CornerRadius="{Binding CornerRadius}">
                        <TextBlock Margin="10" FontFamily="Arial" FontWeight="Bold" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" FontSize="{Binding TextSize}" Foreground="White" Text="{Binding Text}" TextWrapping="Wrap"/>
                    </Border>
                    <Border Name="overlay" Background="Transparent" CornerRadius="{Binding CornerRadius}" />
                </Grid>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding Path=HasBorder}" Value="true">
                        <Setter TargetName="container" Property="BorderThickness" Value="{Binding BorderThickness}" />
                        <Setter TargetName="container" Property="BorderBrush" Value="{Binding BorderBrush}" />
                    </DataTrigger>

                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="overlay" Property="Opacity" Value="0.6" />
                        <Setter TargetName="overlay" Property="Background" Value="Black" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Thank you all for your help,
Komyg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:42:01+00:00Added an answer on May 26, 2026 at 11:42 pm

    I think if you extend the Button class and give it a new boolean DependencyProperty, essentially all you need to do is give your Border a name, then in ControlTemplate.Triggers, Trigger off that boolean property to make the border as you need it in your special cases.

    It would be similar to what you already have with the IsPressed ControlTemplate trigger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my own ControlTemplate for Button, like this: <Style x:Key=LightButtonStyle TargetType={x:Type ButtonBase}>
I have a datagrid in wpf, my cell is <DataGridTextColumn.CellStyle> <Style TargetType=DataGridCell> <Setter Property=Background
I have a custom button,ColorPickerButton, in WPF and style ColorPickerButtonStyle is applied for it,
I have a button control in my wpf-mvvm application. I use an ICommand property
I have a chromeless button in a WPF application that uses the XAML style
I have a WPF button defined like this: <Button Style={StaticResource RevertButtonStyle} /> Here is
I have a WPF grid that contains, among other things, a button. The button
I've deconstructed a standard WPF button using Blend and have managed to create a
I have the following xaml for changing the image for WPF button when mouse
I have a WPF window, which contains a button called Cancel. Under ordinary circumstances

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.