与圆的形象WPF按钮 [英] WPF button with image of a circle

查看:117
本文介绍了与圆的形象WPF按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巴纽彩色圆,剩下的就是透明的。
我能够放置一个按钮,图像,但按钮的风格的其余部分是可见的透明是形象。如何隐藏它,在正常,鼠标和pressed模式?

I have a coloured circle in a .png, the rest is transparent. I am able to place that image on a button but the rest of the button's style is visible on the transparent are of the image. How can I hide it, in normal, mouse over and pressed mode?

推荐答案

试试这个风格

    <Style x:Key="EmptyButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Background" Value="#00000000"/>
        <Setter Property="BorderBrush" Value="#00000000"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <ContentPresenter 
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                        Margin="{TemplateBinding Padding}" 
                        RecognizesAccessKey="True" 
                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

和使用它,如下所示

    <Button Style="{DynamicResource EmptyButtonStyle}">
        <Image Source="/Assets/circle.png" />
    </Button>

这篇关于与圆的形象WPF按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆