• 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: Simple XAML Path Resources

    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/

  • 相关阅读:
    Python时间戳
    vux x-input 清除按钮不起作用
    MySQL连接查询流程源码
    Linux下用的脚本
    TableCache设置过小造成MyISAM频繁损坏 与 把table_cache适当调小mysql能更快地工作
    批量导入数据到InnoDB表速度优化
    DBA面对新mysql环境
    (进阶篇)PHP+Mysql+jQuery找回密码
    (进阶篇)PHP实现用户注册后邮箱验证,激活帐号
    (实用篇)php官方微信接口大全(微信支付、微信红包、微信摇一摇、微信小店)
  • 原文地址:https://www.cnblogs.com/itelite/p/4025621.html
Copyright © 2020-2023  润新知