none
Render buttons without border RRS feed

  • Question

  • Hello,

    I use some buttons containing images in my applications, which are partially transparent. Everything works fine, the only problem is, that a small blue rectangle (border) remains around the buttons. I already tried to remove it, I set BorderThickness to 0,0,0,0 - without success, nothing changed. Is it possible to render a button completely without border or do I have to create a custom control in this case?
    Thank you very much!

    Regards,

    Benjamin
    Wednesday, September 20, 2006 12:12 PM

Answers

  • The blue border is created by ButtonChrome which is a theme-aware decorator, you can romove it from Button's visual tree by redefining the Button's ControlTemplate.

    <Style TargetType="{x:Type Button}">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type Button}">
                  <ContentPresenter
                      Margin="{TemplateBinding Control.Padding}"
                      HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                      VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                      SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
                      ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                      RecognizesAccessKey="True"
                      Content="{TemplateBinding ContentControl.Content}" />
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>

    Add the above xaml into Window.Resources tag.

    Sheva
    Wednesday, September 20, 2006 12:23 PM

All replies

  • The blue border is created by ButtonChrome which is a theme-aware decorator, you can romove it from Button's visual tree by redefining the Button's ControlTemplate.

    <Style TargetType="{x:Type Button}">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type Button}">
                  <ContentPresenter
                      Margin="{TemplateBinding Control.Padding}"
                      HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                      VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                      SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
                      ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                      RecognizesAccessKey="True"
                      Content="{TemplateBinding ContentControl.Content}" />
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>

    Add the above xaml into Window.Resources tag.

    Sheva
    Wednesday, September 20, 2006 12:23 PM
  • Thanks. That helped me a lot :)
    Sometimes, Difficult things are possible... www.cametoofar.com
    Friday, October 28, 2011 6:39 PM