WPF Tips: Button style example

Source: Internet
Author: User
        <Style TargetType="{x:Type Button}" x:Key="TransparentButton">            <Setter Property="Button.Margin" Value="0,5,0,5" />            <Setter Property="Button.Width" Value="16" />            <Setter Property="Button.Height" Value="16" />            <Setter Property="Button.HorizontalAlignment" Value="Left" />            <Setter Property="Button.Background" Value="Transparent" />            <Setter Property="Template">                <Setter.Value>                    <ControlTemplate TargetType="Button">                        <Border Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" x:Name="panel">                            <ContentPresenter Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" />                        </Border>                        <ControlTemplate.Triggers>                            <Trigger Property="IsPressed" Value="true">                                <Setter Property="Background" Value="Transparent" TargetName="panel" />                            </Trigger>                            <Trigger Property="IsMouseOver" Value="true">                                <Setter Property="Background" Value="{x:Static SystemColors.GradientActiveCaptionBrush}" TargetName="panel" />                                <Setter Property="BorderBrush" Value="{x:Static SystemColors.ActiveCaptionBrush}" TargetName="panel" />                                <Setter Property="BorderThickness" Value="1,1,1,1" TargetName="panel"/>                            </Trigger>                        </ControlTemplate.Triggers>                    </ControlTemplate>                </Setter.Value>            </Setter>        </Style>

Application Example:

<Button Grid.Column="2"Style="{StaticResource TransparentButton}"Visibility="{Binding Path=ShowRemoveButton, Converter={StaticResource VisibilityConverter}, Mode=OneWay}"Command="{Binding RemoveTarget}"CommandParameter="{Binding}"><Image Source="..\..\..\Resources\Delete.gif"   HorizontalAlignment="Center" VerticalAlignment="Center"   ToolTip="Remove"/></Button>

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.