我怎么可以给一个WPF元素的长方形扁3D边界? [英] How can I give a WPF element a rectangular flat 3D border?

查看:189
本文介绍了我怎么可以给一个WPF元素的长方形扁3D边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个矩形的平面三维寻找我的控制模板之一。在它的最简单的版本。这意味着具有线在该比暗顶部的底部,也许左右线之间的某些变化太

I would like to create a rectangular 'flat 3D' look for one of my control templates. In it's most simple version this means having a line at the bottom that is darker than that at the top, and maybe some variation between the left and right lines too.

一个更复杂的版本将允许我提供以上的刷子,这样的梯度可以适用。

A more complex version would allow me to provide on or more brushes so that gradients could be applied.

默认< BORDER> 的WPF元素,您可以指定每个边缘的厚度不同,但我不能找到一个方法来指定多个刷子

The default <Border> element in WPF lets you specify a different thickness per edge, but I can't find a way to specify multiple brushes.

所以,我怎么能产生我想要的效果尽可能简单?

So, how can I produce the effect I want as simply as possible?

修改它已经建议我张贴我要如何使用这样的一个例子。个人而言,我会很高兴有一个风格或用户控制。用户控件可能会被这样使用:

EDIT it's been suggested that I post an example of how I want to use this. Personally I'd be happy to have a style or a user control. The user control might be used thus:

<FourSidedBorder LeftSideBrush="#00f" RightSideBrush="#0f0" ... />

也许更简单:

Or perhaps even simpler:

<FourSidedBorder BorderBrush="#00f,#0f0,#f00,#fff"
                 BorderThickness="1,2,3,4" ... />

这些只是想法。任何明智的,简洁的解决方案是值得欢迎的。

These are just ideas. Any sensible, concise solution is welcome.

推荐答案

下面是一个解决方案,我设计,可实现最大的是我想要的。它没有给予完全控制独立于所有四边,但它确实给我想要的矩形平板3D视图。

Here is a solution I devised that achieves most of what I want. It doesn't give complete control over all four sides independently, but it does give the rectangular flat 3D view that I want.

下面是它的外观:

粘贴到 Kaxaml 看到它自己:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Background="#CCC">
  <Page.Resources>
    <!-- A brush for flat 3D panel borders -->
    <LinearGradientBrush x:Key="Flat3DBorderBrush"
                         StartPoint="0.499,0" EndPoint="0.501,1">
      <GradientStop Color="#FFF" Offset="0" />
      <GradientStop Color="#DDD" Offset="0.01" />
      <GradientStop Color="#AAA" Offset="0.99" />
      <GradientStop Color="#888" Offset="1" />
    </LinearGradientBrush>
  </Page.Resources>
  <Grid>  
    <!-- A flat 3D panel -->
    <Border
          HorizontalAlignment="Center" VerticalAlignment="Center"
          BorderBrush="{StaticResource Flat3DBorderBrush}"
          BorderThickness="1" Background="#BBB">

          <!-- some content here -->
          <Control Width="100" Height="100"/>

    </Border>  
  </Grid>
</Page>

希望帮助别人了。我仍然在寻找创新的解决这个问题,所以要发帖,我会接受一个比这更好的答案。

Hope that helps someone else out. I'm still on the lookout for innovative solutions to this problem, so keep posting and I'll accept a better answer than this one.

这篇关于我怎么可以给一个WPF元素的长方形扁3D边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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