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 ...
随机推荐
- 【ipython技巧】使用shell命令
在ipython终端时,可能临时需要使用shell命令进行简单处理: 可以在shell命令前面使用 !(感叹号) 比如在win7,ipython下想要使用sublime新建一个py,可以这样 !sub ...
- 我的AutoCAD二次开发之路 (一)
原帖地址 http://379910987.blog.163.com/blog/static/33523797201011184552167/ 今天在改代码的时候,遇到了AddVertexAt方法的用 ...
- 【python cookbook】【数据结构与算法】4.找到最大或最小的N个元素
问题:想在某个集合中找出最大或最小的N个元素 解决方案:heapq模块中的nlargest()和nsmallest()两个函数正是我们需要的. >>> import heapq &g ...
- php CodeIgniter处理多环境错误级别配置
php CodeIgniter处理多环境错误级别配置 开发者常常希望当系统运行在开发环境或生产环境中时能有不同的行为, 例如,在开发环境如果程序能输出详细的错误信息将非常有用,但是在 生产环境这将造成 ...
- 连接ssh反应很慢,卡,延迟
1.关闭DNS反向解析在linux中,默认就是开启了SSH的反向DNS解析,这个会消耗大量时间,因此需要关闭.# vi /etc/ssh/sshd_configUseDNS=no 在配置文件中,虽然U ...
- NEON简介【转】
转自:http://blog.csdn.net/fengbingchun/article/details/38020265 版权声明:本文为博主原创文章,未经博主允许不得转载. “ARM Advanc ...
- 项目管理:CocoaPods建立私有仓库
CocoaPods是iOS,Mac下优秀的第三方包管理工具,类似于java的maven,给我们项目管理带来了极大的方便. 个人或公司在开发过程中,会积累很多可以复用的代码包,有些我们不想开源,又想像开 ...
- 在discuz二次开发模板时,diy编辑显示我“抱歉,您没有权限添加此模块
<div id="diy_vk_portal_slide_top" class="area"><div id="frameCRxR0 ...
- Chrome开发者工具学习
Chrome开发者工具分为8个大模块,每个模块功能为: 1.Element标签页:用于查看和编辑当前页面中的HTML和CSS元素. 左侧可以看到页面的源码,HTML和CSS元素,双击可以进行修改.右侧 ...
- C/C++获取数组的长度
C.C++中没有提供 直接获取数组长度的函数,对于存放字符串的字符数组提供了一个strlen函数获取长度,那么对于其他类型的数组如何获取他们的长度呢?其中一种方法是使 用sizeof(array) / ...