Windows主题ButtonChrome边框 [英] Windows Themes ButtonChrome Border

查看:207
本文介绍了Windows主题ButtonChrome边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经基于icrosoft_Windows_Themes2:ButtonChrome创建了自己的按钮。我想摆脱默认边框,但我尝试将其设置为null或透明,但仍然得到白色边框。

I have created my own button based on icrosoft_Windows_Themes2:ButtonChrome. I want to get rid of the default border and i've tried setting it to null or transparent but still i get a white border.

这是我的标记:

<Microsoft_Windows_Themes2:ButtonChrome x:Name="ibAero" Visibility="Collapsed" SnapsToDevicePixels="true"  Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" RoundCorners="True" Background="{TemplateBinding Background}" BorderBrush="Transparent" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" OverridesDefaultStyle="True">
    <Border x:Name="bd" CornerRadius="10" BorderThickness="1" BorderBrush="{Binding ElementName=IB, Path=BorderBrush}">
        <StackPanel Orientation="Horizontal" Margin="8,1,5,1">
            <TextBlock Text="{Binding ElementName=IB, Path=Text}" Foreground="{Binding ElementName=IB, Path=TextForeground}" Margin="{Binding ElementName=IB, Path=TextMargin}" VerticalAlignment="Center"/>
        </StackPanel>
    </Border>
</Microsoft_Windows_Themes2:ButtonChrome>

编辑:

好。我已经更改了这样的标记:

Ok. I've changed the markup like this:

<Border x:Name="ibAero" Visibility="Collapsed" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" CornerRadius="3" BorderThickness="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
    <StackPanel x:Name="ibAeroPanel" Orientation="Horizontal" Margin="8,1,5,1">
        <Image Source="{Binding ElementName=IB, Path=Image}" Width="{Binding ElementName=IB, Path=ImageWidth}" Height="{Binding ElementName=IB, Path=ImageHeight}"/>
        <TextBlock Text="{Binding ElementName=IB, Path=Text}" Foreground="{Binding ElementName=IB, Path=TextForeground}" Margin="{Binding ElementName=IB, Path=TextMargin}" VerticalAlignment="Center"/>
    </StackPanel>
</Border>

如何在用户控件中设置默认样式?

How do i set the default style in my usercontrol?

推荐答案

Meleak在以下链接中发布了此问题的答案:

The answer to this problem is posted by Meleak in this link: How to remove ButtonChrome border (when defining the template of a border)?

获得该白色边框的原因是因为它是在ButtonChrome控件中以代码形式添加的。无法通过模板来实现此目的的解决方案。删除边框的唯一方法是编写您自己的控件版本。

The reason you get that white border is because it is added IN CODE in the ButtonChrome control. There is NO WAY to achieve the solution to this with templating. The only way to remove the border is write your own version of the control.

我搜索了此问题,并发现提供模板解决方案的人们找到了许多答案。

I googled this issue and found numerous answers by people offering template "solutions". None of them will ever possibly work as suggested.

将Meleak修改后的ButtonChrome.cs控件添加到自定义WPF控件库中(带有F4禁用键的ComboBox是我个人中的另一个控件)库存),那么您就很好了。

Add Meleak's modified ButtonChrome.cs control to your library of customized WPF controls (ComboBox with disabled F4 key being another in my personal inventory) and you are good to go.

这篇关于Windows主题ButtonChrome边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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