c# - 以斜线为背景的形状

标签 c# .net wpf background shapes

可以画一个 Shape有斜线做的背景吗?

Rectangle 的示例(抱歉图像质量):

enter image description here

如果我想要虚线或更改线条属性(描边、粗细......)?

最佳答案

您可以使用本文中的解决方案 http://mark-dot-net.blogspot.com/2007/06/creating-hatched-patterned-brush-in-wpf.html

<VisualBrush
  x:Key="HatchBrush"
  TileMode="Tile" Viewport="0,0,10,10"
  ViewportUnits="Absolute" Viewbox="0,0,10,10"   
  ViewboxUnits="Absolute">
  <VisualBrush.Visual>
    <Canvas>
       <Rectangle Fill="Azure" Width="10" Height="10" />
       <Path Stroke="Purple" Data="M 0 0 l 10 10" />
    </Canvas>
  </VisualBrush.Visual>
</VisualBrush>

只需更改参数等以适应您的应用

用法:

<Rectangle Width="80" Height="40"
    Fill="{StaticResource HatchBrush}"/>

关于c# - 以斜线为背景的形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11032617/

相关文章:

c# - 如何使用 soap 请求创建 otrs 票证

c# - 如何使用DataGridComboBoxColumn?

.net - 生成 .NET 中多个列的所有可能组合

c# - WPF MVVM : INPC and mediating communication between view model & model

c# - 在上下文菜单 wpf 中禁用多重检查

c# - 如何在 C# 中复制 Python 的排序内置函数的行为?

java - Java 加密与 And .NET 的十六进制生成问题

c# - 具有不同返回类型和参数数量的 Func 委托(delegate)列表

c# - WPF: ListView 在顶部而不是底部显示最近添加的项目

.net - 序列化 .Net SqlTransaction?