http://stackoverflow.com/questions/1003772/setting-margin-properties-in-code

The problem is that Margin is a property, and its type (Thickness) is a value type. That means when you access the property you're getting a copy of the value back.

Even though you can change the value of the Thickness.Left property for a particular value (grr... mutable value types shouldn't exist), it wouldn't change the margin.

Instead, you'll need to set the Margin property to a new value. For instance (coincidentally the same code as Marc wrote):

Thickness margin = MyControl.Margin;
margin.Left = 10;
MyControl.Margin = margin;

As a note for library design, I would have vastly preferred it if Thickness were immutable, but with methods that returned a new value which was a copy of the original, but with one part replaced. Then you could write:

MyControl.Margin = MyControl.Margin.WithLeft(10);

No worrying about odd behaviour of mutable value types, nice and readable, all one expression...

Setting Margin Properties in code的更多相关文章

  1. Set Java Proxy for Http/Https

     Command Line JVM Settings The proxy settings are given to the JVM via command line arguments: java ...

  2. spring mvc DispatcherServlet详解之三---request通过ModelAndView中获取View实例的过程

    整个spring mvc的架构如下图所示: 上篇文件讲解了DispatcherServlet第二步:通过request从Controller获取ModelAndView.现在来讲解第三步:reques ...

  3. linux命令行模式下实现代理上网(转)

    有些公司的局域网环境,例如我们公司的只允许使用代理上网,图形界面的很好解决就设置一下浏览器的代理就好了,但是linux纯命令行的界面就....下面简单几步就可以实现了! 一.命令行界面的一般代理设置方 ...

  4. linux命令行模式下实现代理上网 专题

    有些公司的局域网环境,例如我们公司的只允许使用代理上网,图形界面的很好解决就设置一下浏览器的代理就好了,但是linux纯命令行的界面就....下面简单几步就可以实现了! 一.命令行界面的一般代理设置方 ...

  5. Spring中配置和读取多个Properties文件--转

    public class PropertiesFactoryBeanextends PropertiesLoaderSupportimplements FactoryBean, Initializin ...

  6. Margin and Padding in Windows Forms Controls

    https://msdn.microsoft.com/en-us/library/ms229627.aspx Margin and Padding Precise placement of contr ...

  7. Visual Studio - File Properties (Build Action, Copy to Output Directory)

    Ref: MSDN (https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/0c6xyb ...

  8. util:properties

    示例 <util:properties id="db" location="classpath:db.properties" /> 全部属性 功能概 ...

  9. [转]Entity Framework Fluent API - Configuring and Mapping Properties and Types

    本文转自:https://msdn.microsoft.com/en-us/data/jj591617#1.2 When working with Entity Framework Code Firs ...

随机推荐

  1. 使用Application Loader打包上传AppStore流程

    配置完你的证书,Bundle Identifier 和描述文件的配置 然后配置工程打开你项目工程 第一步,这里不能选择模拟器,选择iOS Device 如果不支持横屏,把这2个勾去掉 然后查看版本号和 ...

  2. Android NDK 开发(二) -- 从Hlello World学起【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41805719  上篇文章讲述了Android NDK开发的一些基本概念,以及NDK ...

  3. 如何杀掉D状态的进程?[zt]【转】

    转自:http://blog.csdn.net/chinalinuxzend/article/details/4288791 [-] 如何杀掉D状态的进程zt 相关博文   原贴:http://www ...

  4. MySQL与SQL比较有那些区别呢

    MySQL是一个逐渐完善的过程,使用前期版本时会遇到一些问题,通常搞得莫名其妙,在版本选择上尽量选择最新的. 1.在5.03以前版本中,存储varchar型数据时,后面的空格会被忽视掉,前面的空格会保 ...

  5. 编码-截取中文-去除HTML字符

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < ...

  6. RAC例子

    我个人非常推崇ReactiveCocoa,它就像中国的太极,太极生两仪,两仪生四象,四象生八卦,八卦生万物.ReactiveCocoa是一个高度抽象的编程框架,它真的很抽象,初看你不知道它是要干嘛的, ...

  7. C#:简单线程样例

    1.定义线程类及内部事件 using System; using System.Collections.Generic; using System.Text; using System.Threadi ...

  8. Linux C socket 编程之TCP

    推荐:http://www.cnblogs.com/tianshuai11/archive/2011/11/30/2477224.html

  9. String 类的常用字符串方法

    public class Page106 { /** * 字符串练习第五章 * @param args */ public static void main(String[] args) { Stri ...

  10. STL MAP及字典树在关键字统计中的性能分析

    转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...