Simple Path Data Resources that I Add to Every WPF and Silverlight Project

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/

时间: 2024-09-30 06:10:28

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

Comprehensive learning path – Data Science in Python

http://blog.csdn.net/pipisorry/article/details/44245575 关于怎么学习python,并将python用于数据科学.数据分析.机器学习中的一篇很好的文章 Comprehensive(综合的) learning path – Data Science in Python Journey from a Pythonnoob(新手) to a Kaggler on Python So, you want to become a data scient

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

http://blog.csdn.net/pipisorry/article/details/44245575 关于怎么学习python,并将python用于数据科学.数据分析.机器学习中的一篇非常好的文章 Comprehensive learning path – Data Science in Python 深度学习路径-用python进行数据学习 Journey from a Pythonnoob(新手) to a Kaggler on Python So, you want to bec

java.lang.ClassNotFoundException: Didn&#39;t find class &quot;*****Activity&quot; on path: /data/app/*******.apk

http://blog.csdn.net/lovexieyuan520/article/details/9032797/ 很多人出现了java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{*****Activity}: java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/app/**

关于java.lang.classNotFoundException:Didn‘t find class “********” Activity&quot;on path:/data/app***.apk异常的总结

最近出现了java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{*****Activity}: java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/app/*******.apk的错误.解决问题如下: 1.Manifest文件中注册的类名称,有没有写错,包名是否写正确. 2.有些第三

WPF Path.Data 后台代码赋值

Path path = new Path(); string sData = "M 250,40 L200,20 L200,60 Z"; var converter = TypeDescriptor.GetConverter(typeof(Geometry)); path.Data = (Geometry)converter.ConvertFrom(sData); 原文地址:https://www.cnblogs.com/lonelyxmas/p/9384685.html

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

今天,在Bulid的过程中,遇到了一个错误“ UnityEditor.BuildPlayerWindow+BuildMethodException: '' is an incorrect path for a scene file. BuildPlayer expects paths relative to the project folder. ",大概意思就是Scenes引用的路径不对,一直以为是自己的Scenes有错,所以重新创建了一个试一下,没有任何卵用,还是一样的错.Google了一下

Android vector Path Data画图详解

SVG是一种矢量图格式,是Scalable Vector Graphics三个单词的首字母缩写.在xml文件中的标签是<vector>,画出的图形可以像一般的图片资源使用,例子如下: <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewpo

Each path can be reduced to a simple path

Recently, I made a small conclusion, but I found it is found and well-founded in some textbook. So I post my paper here. Each_path_can_be_reduced_to_a_simple_path(20181124).pdf Fugures: Figure 1: path reduction Figure 2: two counter examples Figure 3

[]Python][simple]Serialize data with Pickle and deserialize data from pickle

序列化 import pickle friend = {"Dan": [20, "Lodon", 123123], "Mary" : [24, "Madi", 333333]} with open("friend.dat", "wb") as f: pickle.dump(friend, f) 反序列化 with open("friend.dat", "rb