gpt4 book ai didi

wpf - 如何删除 ButtonChrome 边框(定义边框模板时)?

转载 作者:行者123 更新时间:2023-12-04 01:25:26 25 4
gpt4 key购买 nike

我关注了 ChrisF here并写一个 simple demo .

...open your project in Expression Blend, select the button and then right click and select "Edit Template > Edit a Copy..". This copies the existing template into one you can modify. It's easier if you create it in a resource dictionary.



我可以看到按钮的幕后模板,如下图所示(资源中的 ButtonChrome)。

我想删除 ButtonChrome 的白色渐变边框 并保持按钮 UI 的所有其他内容保持原样 .我怎样才能做到这一点?

附:为了使问题简单化,我将 ButtonChrome 用作 View 上的普通控件。我浏览了属性,但仍然不知道在哪里删除“白色”边框。

(正在使用的 ButtonChrome)
alt text

(资源中的 ButtonChrome)
alt text

最佳答案

我不认为有一种简单的方法可以摆脱那个白色边框。实际调用的例程是 DrawInnerBorder,它是从 ButtonChrome 的 OnRender 中调用的。

protected override void OnRender(DrawingContext drawingContext)
{
Rect bounds = new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight);
this.DrawBackground(drawingContext, ref bounds);
this.DrawDropShadows(drawingContext, ref bounds);
this.DrawBorder(drawingContext, ref bounds);

// This one draws the white Rectangle
this.DrawInnerBorder(drawingContext, ref bounds);
}

private void DrawInnerBorder(DrawingContext dc, ref Rect bounds)
{
if ((base.IsEnabled || this.RoundCorners) && ((bounds.Width >= 4.0) && (bounds.Height >= 4.0)))
{
Pen innerBorderPen = this.InnerBorderPen;
if (innerBorderPen != null)
{
dc.DrawRoundedRectangle(null, innerBorderPen, new Rect(bounds.Left + 1.5, bounds.Top + 1.5, bounds.Width - 3.0, bounds.Height - 3.0), 1.75, 1.75);
}
}
}

正如我们所见,没有禁用此功能的属性。
您可以通过设置 IsEnabled="False" 来验证它和 RoundCorners="False"在 ButtonChrome 上或通过将 Width 或 Height 设置为 3.99 之类的值,“白色边框”就会消失。

更新
要禁用 ButtonChrome 的内边框,您可以创建自己的 ButtonChrome 并添加此属性。不幸的是 ButtonChrome 是密封的,所以我们不能继承它。我试图复制整个类并添加属性 DisableInnerBorder 并且它似乎正在工作。你可以像这样使用它
<local:MyButtonChrome ...
DisableInnerBorder="True">

除此之外,它就像常规的 ButtonChrome 一样工作,您还可以添加您可能想要的其他属性等。这种方法可能有我没有想到的缺点,但对于一个小测试,它工作得很好。

显然 937 行代码太多了,无法在 SO 上发布 :) 我在这里上传了 MyButtonChrome.cs: http://www.mediafire.com/?wnra4qj4qt07wn6

关于wpf - 如何删除 ButtonChrome 边框(定义边框模板时)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4553692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com