如何创建具有例如形状的画笔 [英] How to create a brush which has for example shapes

查看:74
本文介绍了如何创建具有例如形状的画笔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


下面的代码显示了a现在如何结合两个矩形来创建画笔.
是否有更快/更快/更少的cpu创建包含形状的画笔的方法?

Hi,
Next code shows how a now combine two rectangles to create a brush.
Is there a quicker/faster/less cpu way to create a brush which contains shapes?

Dim R As New Shapes.Rectangle

R.Stretch = Stretch.Fill

R.Width = 200

R.Height = 200

R.Fill = Brushes.Red



Dim R2 as New Shapes.Rectangle

R2.Stretch = Stretch.Fill

R2.Width = 50

R2.Height = 50

R2.Fill = Brushes.Green



'combine the two rectangles

Dim G As New Grid

G.Children.Add(R)

G.Children.Add(R2)



'create a visual brush

Dim myVisualBrush As New VisualBrush

myVisualBrush.Stretch = Stretch.Fill

myVisualBrush.Visual = G



SomeCanvas.Background = myVisualBrush

推荐答案

您可以通过在xaml中而不是代码中执行此操作来达到相同的目的.这样做的好处是可以节省时间和代码行,在这里看起来很容易.
也可以使用canvas而不是stackPanel或grid 如果您不使用grid或stackpanel的功能,则会为您提供更好的性能

< Canvas x:Name ="LayoutRoot">
 <Canvas.Background>
   < VisualBrush>
    < VisualBrush.Visual>
     <画布>
     <矩形宽度="200"高度="200"填充=红色"/>
      <矩形宽度="50"高度="50"填充=绿色"/>
     </Canvas>
    </VisualBrush.Visual>
   </VisualBrush>
  </Canvas.Background>
 </Canvas>
You can achive same by doing this in xaml instead of code .The advantage is you save time and lines of code and it looks much easier here.
Also use canvas instead of stackPanel or grid if you are not using functionality of grid or stackpanel it will give you better performance

<Canvas x:Name="LayoutRoot">
  <Canvas.Background>
   <VisualBrush>
    <VisualBrush.Visual>
     <Canvas>
      <Rectangle Width="200" Height="200" Fill="Red"/>
      <Rectangle Width="50" Height="50" Fill="Green"/>
     </Canvas>
    </VisualBrush.Visual>
   </VisualBrush>
  </Canvas.Background>
 </Canvas>


这篇关于如何创建具有例如形状的画笔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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