所有的WPF控件列为枚举

代码如:

 1     public enum ControlType
2 {
3 Window_Resources,
4 Page_Resources,
5 Grid,
6 StackPanel,
7 DataGrid,
8 TreeView,
9 TreeViewItem,
10 Button,
11 WrapPanel,
12 Button_CommandParameter,
13 MultiBinding,
14 Binding,
15 TextBox,
16 CheckBox,
17 RadioButton,
18 DataGrid_Columns,
19 DataGridTemplateColumn,
20 DataGridTemplateColumn_CellTemplate,
21 DataTemplate,
22 Border,
23 DataGridTextColumn,
24 ColumnDefinition,
25 RowDefinition,
26 Grid_RowDefinitions,
27 Grid_ColumnDefinitions
28 }

由于枚举不支持小数点.,所以把小数点.改为下划线_

扩展代码为:

  1     public static class XAMLExtend
2 {
3 #region 定义命名空间
4
5 public static XNamespace xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
6 public static XNamespace x = "http://schemas.microsoft.com/winfx/2006/xaml";
7 public static XNamespace mc = "http://schemas.openxmlformats.org/markup-compatibility/2006";
8 public static XNamespace d = "http://schemas.microsoft.com/expression/blend/2008";
9 public static XNamespace local = "clr-namespace:GenesysInfo.MainApp;assembly=GenesysInfo.MainApp";
10 public static XNamespace dic = "clr-namespace:System.Collections.Specialized;assembly=System";
11 public static XNamespace sys = "clr-namespace:System;assembly=mscorlib";
12 public static XNamespace bll = "clr-namespace:GenesysInfo.MainApp.Helper;assembly=GenesysInfo.MainApp";
13 public static XNamespace c = "clr-namespace:GenesysInfo.MainApp.CommandCenter;assembly=GenesysInfo.MainApp";
14 public static XNamespace ctr = "clr-namespace:GenesysInfo.Windows.Controls;assembly=GenesysInfo.ComponentModel";
15 public static XNamespace service = "clr-namespace:GenesysInfo.Data.Service;assembly=GenesysInfo.Data.Service";
16 public static XNamespace data = "clr-namespace:GenesysInfo.Data;assembly=GenesysInfo.Data";
17
18 #endregion
19
20 /// <summary>
21 /// 添加窗体页面命名空间
22 /// </summary>
23 /// <param name="xElement"></param>
24 public static void SetNamespace(this XElement xElement)
25 {
26 xElement.SetAttributeValue(XNamespace.Xmlns + "mc", mc);
27 xElement.SetAttributeValue(XNamespace.Xmlns + "x", x);
28 xElement.SetAttributeValue(XNamespace.Xmlns + "d", d);
29 xElement.SetAttributeValue(XNamespace.Xmlns + "local", local);
30 xElement.SetAttributeValue(XNamespace.Xmlns + "dic", dic);
31 xElement.SetAttributeValue(XNamespace.Xmlns + "sys", sys);
32 xElement.SetAttributeValue(XNamespace.Xmlns + "bll", bll);
33 xElement.SetAttributeValue(XNamespace.Xmlns + "c", c);
34 xElement.SetAttributeValue(XNamespace.Xmlns + "ctr", ctr);
35 xElement.SetAttributeValue(XNamespace.Xmlns + "service", service);
36 xElement.SetAttributeValue(XNamespace.Xmlns + "data", data);
37 }
38
39 /// <summary>
40 /// 添加默认属性
41 /// </summary>
42 /// <param name="xElement"></param>
43 public static void SetDefaultProperty(this XElement xElement)
44 {
45 xElement.Add(new XAttribute(mc + "Ignorable", "d"));
46 xElement.Add(new XAttribute(d + "DesignHeight", "768"));
47 xElement.Add(new XAttribute(d + "DesignWidth", "1024"));
48 }
49
50 /// <summary>
51 /// 设置页面窗体标题
52 /// </summary>
53 /// <param name="xElement"></param>
54 /// <param name="title"></param>
55 public static XElement SetTitle(this XElement xElement, object title)
56 {
57 if (title!=null)
58 xElement.Add(new XAttribute(x + "Title",Convert.ToString(title)));
59 return xElement;
60 }
61
62 /// <summary>
63 /// 设置窗体、页面、控件的名称
64 /// </summary>
65 /// <param name="xElement"></param>
66 /// <param name="name"></param>
67 public static XElement SetName(this XElement xElement, object name)
68 {
69 if (name!=null)
70 xElement.Add(new XAttribute(x + "Name", Convert.ToString(name)));
71 return xElement;
72 }
73
74 /// <summary>
75 /// 设置控件宽高度
76 /// </summary>
77 /// <param name="xElement"></param>
78 /// <param name="width"></param>
79 /// <param name="height"></param>
80 public static XElement SetWH(this XElement xElement,object width, object height)
81 {
82 if (width!=null)
83 xElement.Add(new XAttribute("Width",Convert.ToString(width)));
84
85 if (height!=null)
86 xElement.Add(new XAttribute("Height", Convert.ToString(height)));
87
88 return xElement;
89 }
90
91 /// <summary>
92 /// 设置控件宽度
93 /// </summary>
94 /// <param name="xElement"></param>
95 /// <param name="width"></param>
96 public static XElement SetW(this XElement xElement, object width)
97 {
98 xElement.SetWH(width, null);
99 return xElement;
100 }
101
102 /// <summary>
103 /// 设置控件高度
104 /// </summary>
105 /// <param name="xElement"></param>
106 /// <param name="height"></param>
107 public static XElement SetH(this XElement xElement, object height)
108 {
109 xElement.SetWH(null, height);
110 return xElement;
111 }
112
113 /// <summary>
114 /// 创建控件
115 /// </summary>
116 /// <param name="controlType"></param>
117 /// <returns></returns>
118 public static XElement Create(this ControlType controlType)
119 {
120 return new XElement(xmlns + controlType.GetControlName().Replace("_", "."));
121 }
122
123 /// <summary>
124 /// 在parent中创建子控件
125 /// </summary>
126 /// <param name="parent"></param>
127 /// <param name="controlType"></param>
128 /// <returns></returns>
129 public static XElement AddChildControl(this XElement parent, ControlType controlType)
130 {
131 XElement newXE = Create(controlType);
132 parent.Add(newXE);
133 return newXE;
134 }
135
136 /// <summary>
137 /// 取得控件类型的名称
138 /// </summary>
139 /// <param name="controlType"></param>
140 /// <returns></returns>
141 public static string GetControlName(this ControlType controlType)
142 {
143 return Enum.GetName(typeof(ControlType), controlType);
144 }
145
146 public static XElement SetMinHeight(this XElement xElement, object minHeight)
147 {
148 xElement.Add(new XAttribute("MinHeight",Convert.ToString(minHeight)));
149 return xElement;
150 }
151
152 public static XElement SetMinWidth(this XElement xElement, object minWidth)
153 {
154 xElement.Add(new XAttribute("MinWidth", Convert.ToString(minWidth)));
155 return xElement;
156 }
157
158 public static XElement SetMaxWidth(this XElement xElement, object maxWidth)
159 {
160 xElement.Add(new XAttribute("MaxWidth", Convert.ToString(maxWidth)));
161 return xElement;
162 }
163
164 public static XElement SetMargin(this XElement xElement, object value)
165 {
166 xElement.Add(new XAttribute("Margin", Convert.ToString(value)));
167 return xElement;
168 }
169
170 public static XElement SetContent(this XElement xElement, object text)
171 {
172 xElement.Add(new XAttribute("Content", Convert.ToString(text)));
173 return xElement;
174 }
175
176 public static XElement SetConverter(this XElement xElement, object text)
177 {
178 xElement.Add(new XAttribute("Converter", Convert.ToString(text)));
179 return xElement;
180 }
181
182 public static XElement SetConverterParameter(this XElement xElement, object text)
183 {
184 xElement.Add(new XAttribute("ConverterParameter", Convert.ToString(text)));
185 return xElement;
186 }
187
188 public static XElement SetPath(this XElement xElement, object text)
189 {
190 xElement.Add(new XAttribute("Path", Convert.ToString(text)));
191 return xElement;
192 }
193
194 public static XElement SetOrientation(this XElement xElement, object text)
195 {
196 xElement.Add(new XAttribute("Orientation", Convert.ToString(text)));
197 return xElement;
198 }
199
200 public static XElement SetHorizontalAlignment(this XElement xElement, object text)
201 {
202 xElement.Add(new XAttribute("HorizontalAlignment", Convert.ToString(text)));
203 return xElement;
204 }
205
206 public static XElement SetText(this XElement xElement, object text)
207 {
208 xElement.Add(new XAttribute("Text", Convert.ToString(text)));
209 return xElement;
210 }
211
212 public static XElement SetIsReadOnly(this XElement xElement, object text)
213 {
214 xElement.Add(new XAttribute("IsReadOnly", Convert.ToString(text)));
215 return xElement;
216 }
217
218 public static XElement SetGroupName(this XElement xElement, object text)
219 {
220 xElement.Add(new XAttribute("GroupName", Convert.ToString(text)));
221 return xElement;
222 }
223
224 public static XElement SetTag(this XElement xElement, object text)
225 {
226 xElement.Add(new XAttribute("Tag", Convert.ToString(text)));
227 return xElement;
228 }
229
230 public static XElement SetStyle(this XElement xElement, object text)
231 {
232 xElement.Add(new XAttribute("Style", Convert.ToString(text)));
233 return xElement;
234 }
235
236 public static XElement SetAutoGenerateColumns(this XElement xElement, object text)
237 {
238 xElement.Add(new XAttribute("AutoGenerateColumns", Convert.ToString(text)));
239 return xElement;
240 }
241
242 public static XElement SetCanUserAddRows(this XElement xElement, object text)
243 {
244 xElement.Add(new XAttribute("CanUserAddRows", Convert.ToString(text)));
245 return xElement;
246 }
247
248 public static XElement SetCommand(this XElement xElement, object text)
249 {
250 xElement.Add(new XAttribute("Command", Convert.ToString(text)));
251 return xElement;
252 }
253
254 public static XElement SetHeader(this XElement xElement, object text)
255 {
256 xElement.Add(new XAttribute("Header", Convert.ToString(text)));
257 return xElement;
258 }
259
260 public static XElement SetVisibility(this XElement xElement, object text)
261 {
262 xElement.Add(new XAttribute("Visibility", Convert.ToString(text)));
263 return xElement;
264 }
265
266 public static XElement SetSortDirection(this XElement xElement, object text)
267 {
268 xElement.Add(new XAttribute("SortDirection", Convert.ToString(text)));
269 return xElement;
270 }
271
272 public static XElement SetBinding(this XElement xElement, object text)
273 {
274 xElement.Add(new XAttribute("Binding", Convert.ToString(text)));
275 return xElement;
276 }
277
278 public static XElement SetGrid_Column(this XElement xElement, object text)
279 {
280 xElement.Add(new XAttribute("Grid.Column", Convert.ToString(text)));
281 return xElement;
282 }
283
284 public static XElement SetGrid_Row(this XElement xElement, object text)
285 {
286 xElement.Add(new XAttribute("Grid.Row", Convert.ToString(text)));
287 return xElement;
288 }

XML生成XAMl扩展的更多相关文章

  1. Spring的Xml和JavaConfig 扩展你选哪一个?

    引言 上一篇文章我们有怎么介绍到如何通过XML的形式来定义Spring的扩展<Spring面试高频题如何:自定义XML schema 扩展>,好多人都在吐槽现在都什么年代了,xml还有人再 ...

  2. Difference Between XML and XAML.

    XML, or Extensible Markup Language, is a subset  of the more complex SGML (Standard Generalized Mark ...

  3. 通过xml生成word文档

    Xml生成word总结 使用xml生成word的基本步骤在<使用xslt转化xml数据形成word文档导出.doc>中说明比较清楚了.但是其中的细节并未说到,因此自己折腾了两天总算成功了. ...

  4. 关于XML(可扩展标记语言)的基础知识与写法

    XML(Extensible Markup Language) HTML:超文本标记语言,主要用来展示   XML:可扩展标记语言,用来做数据传输XML特点:1.树状结构,有且只有一个根2.标签名自定 ...

  5. C#操作Xml树的扩展类

    本文提供一个操作Xml树的扩展类,与将xml字符串直接映射成实体对象的使用方法,供大家参考,学习. 下面附上源码 using System; using System.Collections.Gene ...

  6. 根据xml生成相应的对象类

    根据xml生成相应的class对象,听起来很难其实很简单,用xsd.exe就能办到 打开vs 命令行运行xsd.exe 你的xml文件地址 空格/outputdir:存放xsd的地址 ok,这是生成了 ...

  7. spring mvc: xml生成

    spring mvc: xml生成 准备: javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlRootElement ...

  8. XML简介——可扩展标记语言(Extensible Markup Language)

    (What) XML是什么? XML指可扩展标记语言(Extensible Markup Language) 1.  XML是一种标记语言,类似HTML. 2.  XML具有自我描述性 3.  XML ...

  9. x:Static , StaticResource 和DynamicResource等XAML 扩展用法

    原文:x:Static , StaticResource 和DynamicResource等XAML 扩展用法 前提: <system:String x:Key="{Component ...

随机推荐

  1. NABCD-课程表开发

    N:需求 1.学生录入课程需求. 2.学生对于空教室使用需求(自习或活动占用). 3.学生对于具体课程的查询需求. A:做法 基于安卓课程查询,录入系统. B:好处 1.满足课程表的基本需求 2.便于 ...

  2. 安卓出现错误: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText

    Caused by: Java.lang.ClassCastException: Android.widget.TextView cannot be cast to android.widget.Ed ...

  3. java 安装教程

    https://www.cnblogs.com/xuyangblog/p/5455381.html

  4. Interpreting the genomic landscape of speciation: a road map for finding barriers to gene flow

    1.摘要 物种形成是种群间生殖隔离的进化过程,是连续的.复杂的,涉及多个相互作用的屏障.在完成之前,这一过程的影响会随着基因组的不同而变化,并可能导致具有分化和分化波峰和波谷的异质性基因组景观.当基因 ...

  5. Jenkins解析日志(log-parser-plugin)

    Jenkins打包机打包时产生了大量的日志,当报错时,不方便查看error日志 因为日志量太大,查看全部log的时候整个web页面会卡死,所以引用log-parser-plugin可以增加过滤条件显示 ...

  6. Synchronized的几种用法

    https://blog.csdn.net/luoweifu/article/details/46613015

  7. 关于element-ui resetFields

    上周换到新项目组,依然是vue,不过是搭配element-ui. 这两天开始用el-form,发现了个问题. 就是我的表单确定提交之后,需要重置表单,一开始我没看熟API,直接将form对象手动赋成初 ...

  8. 4-16 css

    1.背景是图片 <style> body {background-image:url('bgdesert.jpg');} </style> 2. 十六进制 - 如:" ...

  9. MyEclipse 编译错误 web项目中的 js,jsp报错 更改

    搜索   validation   语法检测 必须 选定一个  不然不编译

  10. 设计模式学习心得<代理模式 Proxy>

    在代理模式(Proxy Pattern)中,一个类代表另一个类的功能.这种类型的设计模式属于结构型模式. 在代理模式中,我们创建具有现有对象的对象,以便向外界提供功能接口. 概述 意图 为其他对象提供 ...