开发者

How to disable border of WPF button when click it?

开发者 https://www.devze.com 2022-12-12 19:10 出处:网络
How to disable border of WPF button when I click it? I have create button like below, everything work fine except when I click on the button.

How to disable border of WPF button when I click it?

I have create button like below, everything work fine except when I click on the button.

<Button Background="Transparent" BorderBrush="Transparent">
    <Button.Content>
        <StackPanel>
            <Image Source="xxx.png" />
            <TextBlock Text="Change Password" />
        </StackPanel>
    </Button.Content>
</开发者_运维百科Button>

When I click the button, it has border like below.

alt text http://www.freeimagehosting.net/uploads/8ece306bd4.png

I try to create style for FocusVisualStyle of the button but it don't work as I expect, this problem also occur when I set IsDefault="True" too.


I know this is an old question, but felt I could answer.

If I understand the problem correctly, after you click the button and move on, a border remains around it. When you click on some other item, like a TextBox or another Button, the border disappears.

This "border" is the "focus" indicator.

To prevent this, set "Focusable" to "False" on the Button:

<Button Background="Transparent" BorderBrush="Transparent" Focusable="False">
    <Button.Content>
        <StackPanel>
            <Image Source="xxx.png" />
            <TextBlock Text="Change Password" />
        </StackPanel>
    </Button.Content>
</Button>


You may have to change the button template, this will give you a button with no frame what so ever, but also without any press or disabled effect:

In your Window.Resources element:

<Style TargetType="Button" x:Key="TransparentButton">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Background="Transparent">
                   <ContentPresenter/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

And the button:

<Button Style="{StaticResource TransparentButton}">
    <Button.Content>
        <StackPanel>
            <Image Source="xxx.png" />
            <TextBlock Text="Change Password" />
        </StackPanel>
    </Button.Content>
</Button>

Now, if you need a little more visual feedback start with this template:

http://msdn.microsoft.com/en-us/library/ms753328.aspx

and remove things until you get what you want.

Don't forget to add a transparent background to your elements, if you don't have one, or have a null background the transparent area inside teh button will not be clickable.

0

精彩评论

暂无评论...
验证码 换一张
取 消