WPF,SilverLight中直线的样式示例

简介: 原文:WPF,SilverLight中直线的样式示例 XAML代码:// LineStyle.xaml                                                           ...
原文: WPF,SilverLight中直线的样式示例

XAML代码:
// LineStyle.xaml
<Viewbox Width="600" Height="500"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Canvas Width="600" Height="500">
        <Canvas.Resources>
            <DrawingBrush x:Key="MyGridBrushResource1" Viewport="0,0,100,100" ViewportUnits="Absolute" TileMode="Tile">
                <DrawingBrush.Drawing>
                    <DrawingGroup>
                        <DrawingGroup.Children>
                            <!--横线-->
                            <GeometryDrawing Geometry="M0,1 L10,1 M0,2 L10,2 M0,3 L10,3 M0,4 L10,4 M0,5 L10,5 M0,6 L10,6 M0,7 L10,7 M0,8 L10,8 M0,9 L10,9">
                                <GeometryDrawing.Pen>
                                    <Pen Thickness="0.1" Brush="#CCCCFF" />
                                </GeometryDrawing.Pen>
                            </GeometryDrawing>
                            <!--竖线-->
                            <GeometryDrawing Geometry="M1,0 L1,10 M2,0 L2,10 M3,0 L3,10 M4,0 L4,10 M5,0 L5,10 M6,0 L6,10 M7,0 L7,10 M8,0 L8,10 M9,0 L9,10">
                                <GeometryDrawing.Pen>
                                    <Pen Thickness="0.1" Brush="#CCCCFF" />
                                </GeometryDrawing.Pen>
                            </GeometryDrawing>
                            <!-- 这里是横线 -->
                            <GeometryDrawing Geometry="M0,0 L10,0">
                                <GeometryDrawing.Pen>
                                    <Pen Thickness="0.1" Brush="DarkOrange" />
                                </GeometryDrawing.Pen>
                            </GeometryDrawing>
                            <!-- 这里是竖线 -->
                            <GeometryDrawing Geometry="M0,0 L0,10">
                                <GeometryDrawing.Pen>
                                    <Pen Thickness="0.1" Brush="DarkOrange" />
                                </GeometryDrawing.Pen>
                            </GeometryDrawing>
                        </DrawingGroup.Children>
                    </DrawingGroup>
                </DrawingBrush.Drawing>
            </DrawingBrush>

            <!-- 这里是外框线 -->
            <Style x:Key="MyGridBorderStyle">
                <Setter Property="Border.Background" Value="{StaticResource MyGridBrushResource1}"/>
                <Setter Property="Border.HorizontalAlignment" Value="Center"/>
                <Setter Property="Border.VerticalAlignment" Value="Top"/>
                <Setter Property="Border.BorderBrush" Value="Black"/>
                <Setter Property="Border.BorderThickness" Value="1"/>
            </Style>
        </Canvas.Resources>

        <Border Style="{StaticResource MyGridBorderStyle}">
            <Canvas Width="630" Height="400">
                <Line Stroke="Black" X1="0" Y1="20" X2="400" Y2="20" StrokeDashArray="1,1" StrokeThickness="30"/>
                <Line Stroke="Black" X1="0" Y1="60" X2="400" Y2="60" StrokeDashArray="1,1,2" StrokeThickness="30" />
                <Line Stroke="Black" X1="0" Y1="100" X2="400" Y2="100" StrokeDashArray="1,1,2,2"
   StrokeThickness="30"  StrokeDashCap="Round" StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />
                <Line Stroke="Black" X1="0" Y1="140" X2="400" Y2="140" StrokeDashArray="1,1,2,2" StrokeThickness="30"
   StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />

                <Line Stroke="Black" X1="0" Y1="180" X2="400" Y2="180" StrokeDashArray="0,1"
   StrokeThickness="30" StrokeDashCap="Round" StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />

                <Line Stroke="Black" X1="0" Y1="220" X2="400" Y2="220" StrokeDashArray="0,2" StrokeThickness="30"
   StrokeDashCap="Round" StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />

                <Line Stroke="Black" X1="0" Y1="260" X2="400" Y2="260" StrokeDashArray="0,2,0,2" StrokeThickness="30"
   StrokeDashCap="Round" StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />

                <Line Stroke="Black" X1="0" Y1="300" X2="400" Y2="300" StrokeDashArray="0,1,1" StrokeThickness="30"
   StrokeDashCap="Round" StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />

                <Line Stroke="Black" X1="0" Y1="340" X2="400" Y2="340" StrokeDashArray="0,2,1,0" StrokeThickness="30"
   StrokeDashCap="Round" StrokeStartLineCap="Round"  StrokeEndLineCap="Round" />

            </Canvas>
        </Border>
    </Canvas>
</Viewbox>

运行效果:WPF,SilverLight中直线的样式

目录
相关文章
WPF疑难问题之Treeview中HierarchicalDataTemplate多级样式
WPF疑难问题之Treeview中HierarchicalDataTemplate多级样式
348 0
|
3月前
|
C# Windows 开发者
当WPF遇见OpenGL:一场关于如何在Windows Presentation Foundation中融入高性能跨平台图形处理技术的精彩碰撞——详解集成步骤与实战代码示例
【8月更文挑战第31天】本文详细介绍了如何在Windows Presentation Foundation (WPF) 中集成OpenGL,以实现高性能的跨平台图形处理。通过具体示例代码,展示了使用SharpGL库在WPF应用中创建并渲染OpenGL图形的过程,包括开发环境搭建、OpenGL渲染窗口创建及控件集成等关键步骤,帮助开发者更好地理解和应用OpenGL技术。
245 0
|
3月前
|
开发者 C# 存储
WPF开发者必读:资源字典应用秘籍,轻松实现样式与模板共享,让你的WPF应用更上一层楼!
【8月更文挑战第31天】在WPF开发中,资源字典是一种强大的工具,用于共享样式、模板、图像等资源,提高了应用的可维护性和可扩展性。本文介绍了资源字典的基础知识、创建方法及最佳实践,并通过示例展示了如何在项目中有效利用资源字典,实现资源的重用和动态绑定。
81 0
|
3月前
|
开发者 C# 存储
WPF开发者必读:样式与模板的艺术,轻松定制UI外观,让你的应用程序更上一层楼!
【8月更文挑战第31天】在WPF应用开发中,样式与模板是实现美观界面与一致性的关键工具。样式定义了控件如字体、颜色等属性,而模板则允许自定义控件布局与子控件,两者均可存储于`.xaml`文件中。本文介绍了样式与模板的基础知识,通过示例展示了如何创建并应用它们来改变按钮的外观,从而提升用户体验。
79 0
|
C# 数据安全/隐私保护
【WPF】右下角弹出自定义通知样式(Notification)——简单教程
原文:【WPF】右下角弹出自定义通知样式(Notification)——简单教程 1.先看效果 2.实现 1.主界面是MainWindow 上面就只摆放一个Button即可。
3051 0
|
3月前
|
存储 前端开发 C#
WPF/C#:更改界面的样式
WPF/C#:更改界面的样式
43 0
WPF-布局样式练习-Day02-聊天气泡
WPF-布局样式练习-Day02-聊天气泡
237 1
|
6月前
|
C#
浅谈WPF之样式与资源
WPF通过样式,不仅可以方便的设置控件元素的展示方式,给用户呈现多样化的体验,还简化配置,避免重复设置元素的属性,以达到节约成本,提高工作效率的目的,样式也是资源的一种表现形式。本文以一个简单的小例子,简述如何设置WPF的样式以及资源的应用,仅供学习分享使用,如有不足之处,还请指正。
119 0
WPF-Binding问题-模板样式使用Binding TemplatedParent与TemplateBinding区别
WPF-Binding问题-模板样式使用Binding TemplatedParent与TemplateBinding区别
217 0
WPF-样式问题-处理ListBox、ListView子项内容全填充问题
WPF-样式问题-处理ListBox、ListView子项内容全填充问题
230 0

热门文章

最新文章