Here’s a little time saver. I sort of have a routine that I go through when I create a new WPF project. One of those things is to create a resource dictionary (I’m down to one on most projects now, but more on that later) that includes some common stuff that is nice to be able to depend on while your cranking out XAML.

Among those, are these super simple geometry resources:


<Geometry x:Key="DownArrow">M0,0 L1,0 0.5,1Z</Geometry>
<Geometry x:Key="UpArrow">M0,1 L1,1 0.5,0Z</Geometry>
<Geometry x:Key="RightArrow">M0,0 L1,0.5 0,1Z</Geometry>
<Geometry x:Key="LeftArrow">M0,0.5 L1,1 1,0Z</Geometry>
<Geometry x:Key="CloseX">M0,0 L1,1 M0,1 L1,0</Geometry>

Simple, but handy when you (inevitably) need to bust out an arrow for some reason. You use them like this:


<!-- DownArrow -->
<Path Data="{StaticResource DownArrow}" Width="10" Height="8"
Stretch="Fill" Fill="Black" /> <!-- CloseX -->
<Path Data="{StaticResource CloseX}" Width="12" Height="12"
Stretch="Fill" Stroke="Black" StrokeThickness="3" Margin="10" />

All together, they look like this: 

The geometries themselves all happen within a real coordinate space of a pixel, so it’s important to set the Stretch property to Fill, that way the geometry with stretch to the size of the Path element.

Unfortunately, this is WPF only. Silverlight (SL2 at least) doesn’t like to work with Geometries as resources. If someone tries it out in SL3, let me know how it goes.

Update: Dr. WPF (ironically) suggested a sweet workaround for Silverlight. Instead of adding the resources as Geometries, add them as strings, like this:


<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Grid.Resources>
<sys:String x:Key="DownArrow">M0,0 L1,0 0.5,1Z</sys:String>
<sys:String x:Key="UpArrow">M0,1 L1,1 0.5,0Z</sys:String>
<sys:String x:Key="RightArrow">M0,0 L1,0.5 0,1Z</sys:String>
<sys:String x:Key="LeftArrow">M0,0.5 L1,1 1,0Z</sys:String>
<sys:String x:Key="CloseX">M0,0 L1,1 M0,1 L1,0</sys:String>
</Grid.Resources>
</Grid>

The usage from XAML is then exactly the same as WPF. Nice one, doc!

from:http://nerdplusart.com/simple-path-data-resources-that-i-add-to-every-wpf-project/

Simple Path Data Resources that I Add to Every WPF and Silverlight Project的更多相关文章

  1. the core of Git is a simple key-value data store The objects directory stores all the content for your database

    w https://git-scm.com/book/en/v1/Git-Internals-Plumbing-and-Porcelain Git is a content-addressable f ...

  2. Comprehensive learning path – Data Science in Python深入学习路径-使用python数据中学习

    http://blog.csdn.net/pipisorry/article/details/44245575 关于怎么学习python,并将python用于数据科学.数据分析.机器学习中的一篇非常好 ...

  3. UWP中String 转为Path Data

    定义方法: Geometry PathMarkupToGeometry(string pathMarkup) { string xaml = "<Path " + " ...

  4. java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/app/*******.apk

    http://blog.csdn.net/lovexieyuan520/article/details/9032797/ 很多人出现了java.lang.RuntimeException: Unabl ...

  5. 巨坑npm run dev 报错 终于找到正确答案 Error: EPERM: operation not permitted, open '/data/public/build/css/add.p

    Windows10环境 npm run dev 报错  终于找到正确答案 Error: EPERM: operation not permitted, open '/data/public/build ...

  6. WPF Path.Data 后台代码赋值

    Path path = new Path(); string sData = "M 250,40 L200,20 L200,60 Z"; var converter = TypeD ...

  7. Hadoop 格式化namenode时报错警告:WARN common.Util: Path /data/dfs/name should be specified as a URI in configuration

    格式化namenode时报错警告:WARN common.Util: Path /data/dfs/name should be specified as a URI in configuration ...

  8. Bulid过程中中遇到的问题UnityEditor.BuildPlayerWindow+BuildMethodException: '' is an incorrect path for a scene file. BuildPlayer expects paths relative to the project folder.

    今天,在Bulid的过程中,遇到了一个错误“ UnityEditor.BuildPlayerWindow+BuildMethodException: '' is an incorrect path f ...

  9. 【转】Comprehensive learning path – Data Science in Python

    Journey from a Python noob to a Kaggler on Python So, you want to become a data scientist or may be ...

随机推荐

  1. win10下快捷命令

    win10下可在win+r的输入框中: 1.gpedit.msc   //本地组策略编辑器 2.regedit    //注册表 3.secpol.msc   //本地安全策略 4.mstsc    ...

  2. SQL存储过程教程

      一直以来,对SQL SERVER的存储过程和触发器都基本没有用到,只是偶尔从网上找几个简单的函数PASTE到我的SQL中用.自己写总是感觉缺点什么,前几天单位的培训讲了一天的SQL SERVER, ...

  3. K8s 介绍

    Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群间扩展. 使用Kubernetes可以: 1. 自动化容器的部署和复制 2. 随时扩展或收缩容器规模 3. 将 ...

  4. zabbix 实现 iptables 监控

    安装iptstate # yum install iptstate 配置zabbix key iptables.conf # cat /etc/zabbix/zabbix_agentd.d/iptab ...

  5. SAP NetWeaver BW 7.3介绍

    (摘自SAP 官方 EIM300 SAP NetWeaver BW 7.3 特色功能.前景展望与路线图)

  6. CentOS 7修改管理员密码

    之前安装CentOS 7的时候随便输入了一个密码,现在使用需要root权限,只能重置密码了.下面是处理方法:(进入单用户模式修改root密码为例) 在启动菜单中,按e编辑所选启动项 一页内容,感觉挺陌 ...

  7. 如何用SpringBoot框架来接收multipart/form-data文件

    https://blog.csdn.net/linzhiqiang0316/article/details/77016997 ************************************* ...

  8. js生成二维码实例

    <!DOCTYPE html><html><head>    <title></title>    <meta charset=&qu ...

  9. uboot——之初体验

    官方下载地址:ftp://ftp.denx.de/pub/u-boot/ uboot的终极奥义就是启动内核. 但是,现在,我们先做最基本的,去官网下载一个支持自己板子的uboot,然后解压缩,打补丁. ...

  10. linux下保护视力、定时强制锁定软件: Workrave

    超负荷地工作会累坏身体的,而且效率也不高,所以工作一段时间就应该休息一下.长时间在电脑前一动不动,很容易患上“重复性劳损”,即 Repetitive Strain Injury (RSI).具体现象大 ...