Setting Margin Properties in code
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的更多相关文章
- Set Java Proxy for Http/Https
Command Line JVM Settings The proxy settings are given to the JVM via command line arguments: java ...
- spring mvc DispatcherServlet详解之三---request通过ModelAndView中获取View实例的过程
整个spring mvc的架构如下图所示: 上篇文件讲解了DispatcherServlet第二步:通过request从Controller获取ModelAndView.现在来讲解第三步:reques ...
- linux命令行模式下实现代理上网(转)
有些公司的局域网环境,例如我们公司的只允许使用代理上网,图形界面的很好解决就设置一下浏览器的代理就好了,但是linux纯命令行的界面就....下面简单几步就可以实现了! 一.命令行界面的一般代理设置方 ...
- linux命令行模式下实现代理上网 专题
有些公司的局域网环境,例如我们公司的只允许使用代理上网,图形界面的很好解决就设置一下浏览器的代理就好了,但是linux纯命令行的界面就....下面简单几步就可以实现了! 一.命令行界面的一般代理设置方 ...
- Spring中配置和读取多个Properties文件--转
public class PropertiesFactoryBeanextends PropertiesLoaderSupportimplements FactoryBean, Initializin ...
- Margin and Padding in Windows Forms Controls
https://msdn.microsoft.com/en-us/library/ms229627.aspx Margin and Padding Precise placement of contr ...
- 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 ...
- util:properties
示例 <util:properties id="db" location="classpath:db.properties" /> 全部属性 功能概 ...
- [转]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 ...
随机推荐
- 天天模拟器 和 Genymotion 设置代理
之前以为是10.0.3.1或者本机IP,尝试几次都不行,百度之,得到答案,原来genymotion里面网关的IP是10.0.3.2 所以,代理IP要设置为:10.0.3.2
- Mac OX 隐藏文件夹,文件,应用,磁盘的2种方法 hide finder folder, file, application, volume in 2 ways
经常需要主目录下隐藏一些文件夹之类的, 第一想到的当然就是:在要隐藏的文件夹前面加『.』(leading dot),这个用法当然可以的了 用习惯了Linux/GNU系统的,基本习惯使用这种办法 但是, ...
- List对象排序的通用方法
转自 @author chenchuang import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Me ...
- 【jqGrid for ASP.NET MVC Documentation】.学习笔记.1.介绍
1 介绍 jqGrid for ASP.NET MVC 是一个服务端组件. 专为MVC 分隔 model ,view , controller 的原则,完全观察者模式 非常快的速度 仅仅很 ...
- 4、BOM编程/正则表达式
1. BOM编程 1.1. BOM编程基础 全称 Browser Object Model,浏览器对象模型. JavaScript是由浏览器中内置的javascript脚本解释器程序来执行jav ...
- 完整学习git四git对象
1查看git对象 git cat-file 实践 git head到底指向的是什么 ➜ gittest git:(master) find .git -name HEAD -o -name maste ...
- [BIM]STEP标准和EXPRESS语言
参考:http://blog.sina.com.cn/s/blog_620be62e0100iqyb.html (BIM名词和术语(四)- IFC/STEP/EXPRESS) IFC标准使用形式化的数 ...
- python 路径
atm---main.py import os ,sys print(__file__) print(os.path.abspath(__file__))#绝对路径 print(os.path.dir ...
- 【转】SVN建库方法
转载地址:http://blog.csdn.net/winonatong/article/details/5791919 SVN全名Subversion,即版本控制系统.SVN与CVS一样,是一个跨平 ...
- hdu4924 Football Manager
这题上来我是没有思路的.因为目标值关涉到的因素太多而直接枚举的复杂度又太高. 目标值由两部分合成,一部分是队员的CA和与PA和,另一部分是队员之间的relationship. 前者是简单的代数累加,而 ...