所有的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. 第一次C语言程序设计

    C语言程序实验报告 实验项目: 1.字符与ASCII码 2.运算符与表达式的应用 3.顺序结构应用程序 4.数学函数的算法描述 5.鸡兔同笼的算法描述 6.确定坐标的算法描述 姓名:张时锋 实验地点: ...

  2. cuts

    1.cuts .replacename.fasta..replacename.fasta..replacename.fasta.cut.list awk 'system("mv Dme49. ...

  3. C# 微信网页授权多域名解决

    在做微信开发的时候,会遇到这样的场景:一个公众号,会有多个业务:官网.论坛.商城等等 微信网页授权域名 目前最多可以填写两个!!!,那么问题来了?这应该怎么办? 答案就是: 做一个中转服务! 域名1: ...

  4. 【Spring学习】Spring的源码解析之路

    缘起:=====>>>> 在项目中实际上是用到了Spring的内容,只是直接用的SpringBoot,不管是Eclipse中还是在Intellig IDEA中,应该都比较容易能 ...

  5. 【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. Example 1 ...

  6. NoteBook学习(一)-------- Zeppelin VS Jupyter

    notebook1.mdhtml, body {overflow-x: initial !important;}html { font-size: 14px; color: rgb(51, 51, 5 ...

  7. 分析abex-crackme#1

    1.分析环境2.运行程序,了解大致的运行过程3.运行Ollydbg调试程序3.1.分析结果简述4.破解4.1.方法一4.2.方法二5.运行结果6.与书中不同之处 1.分析环境 操作系统:Win10 1 ...

  8. Unity 角色移动贴墙行走

    直接贴上代码,旋转角色角度检测碰撞 Vector2 v2Normal = new Vector2(normal.x, normal.y); float fAngle = Vector2.SignedA ...

  9. PHP整理--MySQL--DOS命令操作数据库

    一.MySQL:关系型数据库,存在表的概念. MySQL的结构:数据库可以存放很多表,每张表可以存放多个字段,每个字段可以存放多个记录. 二.Dos操作数据库 用PHPStudy终端➡其他选项菜单➡M ...

  10. java反射调用dubbo接口

    需求:项目增加幂等 场景:1.三个项目:a .b.c2.a项目加幂等3.b项目dubbo调用项目a的时候超时没有获取返回结果,增加重试机制(非立即重试,3min or 5min 后重试)4.c项目是一 ...