在WPF中将borderbrush设置为LinearGradientBrush

发布于 2024-12-04 17:26:09 字数 465 浏览 3 评论 0原文

我是 WPF 新手,仍然遇到一些基本问题。

我有一个来自 devcomponents 的控件,默认为蓝色边框。我的文本框等有更灰色的颜色。我希望 devcomponents 控件具有相同的边框。

我查看 TextBox 的属性,发现 BorderBrush 设置为“System.Windows.Media.LinearGradientBrush”,但我无法放置 -

<WpfEditors:IntegerInput BorderBrush="System.Windows.Media.LinearGradientBrush"...

事实上,我无法放置 -

<TextBox BorderBrush="System.Windows.Media.LinearGradientBrush" ...

我错过了什么魔力?

谢谢。

I'm new to WPF and still having some basic problems.

I have a control from devcomponents that defaults to a blue border. My textboxes etc. have a more grey colour. I want the devcomponents control to have the same border.

I look in the properties of a TextBox and see that BorderBrush is set to "System.Windows.Media.LinearGradientBrush" yet I can't put -

<WpfEditors:IntegerInput BorderBrush="System.Windows.Media.LinearGradientBrush"...

In fact, I can't put -

<TextBox BorderBrush="System.Windows.Media.LinearGradientBrush" ...

What magic am I missing?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-12-11 17:26:09

您必须为属性 BorderBrush 分配一个 Brush(正如您可以通过其名称猜到的那样)。

Brush 的一种是 LinearGradientBrush(在颜色之间产生渐变的东西)
SolidColorBrush 是另一种也可以被分配的画笔。

看起来您使用的这种控件已经分配了一个LinearGradientBrush
现在您可以分配您选择的画笔并覆盖已设置的画笔。

LinearGradientBrush 示例:

<TextBox>
  <TextBox.BorderBrush>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
      <GradientStop Color="Black" Offset="0.0" />
      <GradientStop Color="White" Offset="1" />
    </LinearGradientBrush>
  </TextBox.BorderBrush>
</TextBox>

如果您希望边框仅采用纯色,您也可以使用 SolidColorBrush

  <TextBox.BorderBrush>
    <SolidColorBrush Color="Red" />
  </TextBox.BorderBrush>

或者只使用现有的转换器颜色 --> SolidColorBrush

<TextBox BorderBrush="Red" Text="bla bla" />

编辑:

如果您希望所有控件都具有相同的边框,您可以将 Brush 添加到容器对象的 ResourceDictionary 中,并将其重用于所有控件。 。

<!-- Add the Brush as resource to the surrounding window -->
<Window.Resources>
  <SolidColorBrush x:Key="controlBorderBrush" Color="Gray" />
</Window.Resources>

<!-- -->
<TextBlock BorderBrush="{StaticResource controlBorderBrush}" Text="huhuuu" />
<otherlib:SpecialTextBlockWithOverriddenProps BorderBrush="{StaticResource controlBorderBrush}" Text="hahaaaaaaa" />

To the property BorderBrush you have to assign a Brush (as you could guess by its name).

One kind of Brush is a LinearGradientBrush (the thing which makes a gradient between colors)
SolidColorBrush is another kind of Brush which could also get assigned.

As it looks as this kind of control you use has already assigned a LinearGradientBrush.
Now you can assign a Brush of your choice and override the already set Brush.

Example for a LinearGradientBrush:

<TextBox>
  <TextBox.BorderBrush>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
      <GradientStop Color="Black" Offset="0.0" />
      <GradientStop Color="White" Offset="1" />
    </LinearGradientBrush>
  </TextBox.BorderBrush>
</TextBox>

If you want your border just in a a solid color you can also use a SolidColorBrush.

  <TextBox.BorderBrush>
    <SolidColorBrush Color="Red" />
  </TextBox.BorderBrush>

or just use the existing Converter Color --> SolidColorBrush

<TextBox BorderBrush="Red" Text="bla bla" />

EDIT:

And if you want that all your controls have the same Border you can add a Brush to the ResourceDictionary of a container object and reuse it for all the controls...

<!-- Add the Brush as resource to the surrounding window -->
<Window.Resources>
  <SolidColorBrush x:Key="controlBorderBrush" Color="Gray" />
</Window.Resources>

<!-- -->
<TextBlock BorderBrush="{StaticResource controlBorderBrush}" Text="huhuuu" />
<otherlib:SpecialTextBlockWithOverriddenProps BorderBrush="{StaticResource controlBorderBrush}" Text="hahaaaaaaa" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文