【问题标题】:Windows Themes ButtonChrome BorderWindows 主题按钮Chrome 边框
【发布时间】:2010-07-29 15:13:20
【问题描述】:

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

这是我的标记:

<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>

编辑:

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

<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>

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

【问题讨论】:

    标签: wpf button controls


    【解决方案1】:

    这个问题的答案由 Meleak 发布在这个链接中:How to remove ButtonChrome border (when defining the template of a border)?

    你得到那个白色边框的原因是因为它是在 ButtonChrome 控件中添加的。没有办法通过模板来解决这个问题。删除边框的唯一方法是编写您自己的控件版本。

    我在谷歌上搜索了这个问题,并通过提供模板“解决方案”的人找到了许多答案。它们都不可能按建议工作。

    将 Meleak 修改后的 ButtonChrome.cs 控件添加到您的自定义 WPF 控件库(禁用 F4 键的组合框是我个人库存中的另一个),您就可以开始了。

    【讨论】:

      【解决方案2】:

      我建议不要在您的模板中包含 Button Chrome。如果您想重新创建它在鼠标悬停和按下时提供的一些不错的效果,则需要额外的工作,但它会摆脱边框。

      【讨论】:

      • 如何在我的用户控件中设置默认样式?
      猜你喜欢
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-28
      相关资源
      最近更新 更多