本文介绍了如何(定义边框模板时)删除ButtonChrome边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着 ChrisF 的谱写<一个href=\"https://docs.google.com/uc?id=0B0fBOJ9vvqOfZjA0NDI5MGEtY2E1Yi00ODYzLWJmMWEtMjU3MmQyZmNkYjQ3&export=download&hl=en_US\">simple演示。

...防爆pression Blend中打开你的项目,
  选择按钮,然后点击右键
  并选择编辑模板>编辑
  复制...。这会将现有的
  模板到一个你可以修改。它的
  如果您在资源创建更容易
  字典。

我可以看到按钮的背后的屏幕模板下面的截图(中的在资源ButtonChrome 的)。

And I can see the behind-the-screen template of the button as below screenshot (The ButtonChrome in Resource).

我要删除的 ButtonChrome 并保留一切按钮的用户界面的白渐变边框保​​持原样。我该怎么做?

I want to remove the white-gradient border of the ButtonChrome AND keep everything else of the button's UI remain as-is. How can I do that?

PS。为了使问题简单我用ButtonChrome作为我认为一个正常的控制。我浏览属性,但仍然有不知道从哪里取出白的边界。

ps. To make the problem simple I use the ButtonChrome as a normal control on my view. I browse the properties but still got NO idea where to remove the "white" border.

(即 ButtonChrome 的使用中)

(The ButtonChrome in-use)

(即 ButtonChrome 的资源型)

(The ButtonChrome in Resource)

推荐答案

我不认为有一个简单的方法来摆脱白色边框。被称为实际的程序是DrawInnerBorder其从内部的OnRender在ButtonChrome调用。

I don't think there's an easy way to get rid of that White Border. The actual routine being called is DrawInnerBorder and its called from within OnRender in ButtonChrome.

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或通过设置宽度或高度为类似3.99和白边消失了。

As we can see, there is no property to disable this.You can verify it by setting IsEnabled="False" and RoundCorners="False" on the ButtonChrome or by setting Width or Height to something like 3.99 and the "White Border" goes away.

更新结果
要禁用ButtonChrome的内边框,你可以创建自己的ButtonChrome这将增加该属性。不幸的是ButtonChrome是密封的,所以我们不能继承​​它。我试图复制整个类,并添加属性DisableInnerBorder,它似乎是工作。你可以使用它像这样

Update
To disable the inner border of ButtonChrome you could create your own ButtonChrome which adds this property. Unfortunately ButtonChrome is sealed so we can't inherit from it. I tried to copy the whole class and add the Property DisableInnerBorder and it seems to be working. You can use it like this

<local:MyButtonChrome ...
                      DisableInnerBorder="True">

除此之外,它的工作原理就像普通ButtonChrome,你还可以添加其他属性等,你可能希望。可能有缺点,这个方法是我没有想到的,但对于一个小的测试,它的工作就好了。

Other than that it works just like the regular ButtonChrome and you can also add other Properties etc. that you might want. There might be drawbacks to this method that I haven't thought of, but for a small test it worked just fine.

code的Apperently 937线是太多SO张贴:)我上传MyButtonChrome.cs此处的

Apperently 937 lines of code was too much to post on SO :) I uploaded MyButtonChrome.cs here: http://www.mediafire.com/?wnra4qj4qt07wn6

这篇关于如何(定义边框模板时)删除ButtonChrome边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:53