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. keepAlive参数详解

    最近研究netty5.0中 发现http例子里面有关于KeepAlive的处理,于是研究了下 http://www.nowamagic.net/academy/detail/23350305

  2. WCF学习分享2

    整个solution结构例如以下: 以下介绍每一个project: 1. Service.Interface 定义契约 ICalculator.cs watermark/2/text/aHR0cDov ...

  3. zabbix 实现 iptables 监控

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

  4. 用casperjs模拟登录,支持多个账户登录

    var casper = require('casper').create({ viewportSize:{ width:1920, height:1080 } }); var url1 = 'htt ...

  5. 【小白的CFD之旅】20 计算区域的构建

    计算域是什么计算域如何创建常用的建模软件计算域几何的特殊之处具体的计算域提取方法小白总结 自从上次在食堂听了小牛师兄关于计算网格的一些问题后,小白决定在寒假期间好好的补习一下关于计算网格的划分内容.在 ...

  6. Linux--多网卡的7种Bond模式【转】

    转自:http://www.cnblogs.com/lcword/p/5914089.html 网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡.在应用部署中是一 ...

  7. Ubuntu 安装 mysql

    sudo apt-get install mysql-server sudo apt install mysql-client sudo apt install libmysqlclient-dev

  8. tf.truncated_normal

    tf.truncated_normal truncated_normal( shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name ...

  9. Android开发(八)——Android组件

    参考: [1] Android开发教程:理解Intent和Intent Filter.http://liuzhichao.com/p/506.html

  10. Apache重写RewriteCond

    RewriteCond就像我们程序中的if语句一样,表示如果符合某个或某几个条件则执行RewriteCond下面紧邻的RewriteRule语句,这就是RewriteCond最原始.基础的功能,为了方 ...