当前位置: 首页>>代码示例>>C#>>正文


C# CheckBox.CreateBinding方法代码示例

本文整理汇总了C#中System.Windows.Controls.CheckBox.CreateBinding方法的典型用法代码示例。如果您正苦于以下问题:C# CheckBox.CreateBinding方法的具体用法?C# CheckBox.CreateBinding怎么用?C# CheckBox.CreateBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.CheckBox的用法示例。


在下文中一共展示了CheckBox.CreateBinding方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSimpleItemsControl

		public FrameworkElement GetSimpleItemsControl() {
			StackPanel spanel = new StackPanel();
			spanel.Orientation = Orientation.Vertical;

			var simplelist = InitSimpleItems();

			simplelist.Where(x => x.isPresent).ForEach(x => {
				var sitem = config.parameters.simpleItem.FirstOrDefault(si => si.name == x.xname);
				if (sitem != null) {
					spanel.Children.Add(GetSimpleEditorCtrl(x.xtype, sitem.name, sitem));
				}
			});
			simplelist.Where(x => !x.isPresent).ForEach(x => {
				var sitem = new ItemList.SimpleItem() {
					name = x.xname,
					value = ""
				};

				FrameworkElement elem = GetSimpleEditorCtrl(x.xtype, x.xname, sitem);

				CheckBox chBox = new CheckBox();
				chBox.Margin = new Thickness(40, 0, 0, 0);
				chBox.Content = "Is element enabled";
				chBox.CreateBinding(CheckBox.IsCheckedProperty, (itemDescr)x, s => {
					elem.IsEnabled = s.isPresent;
					return s.isPresent;
				}, (o, v) => {
					o.isPresent = v;
					if (v) {
						elem.IsEnabled = true;
						if (config.parameters != null && config.parameters.simpleItem != null) {
							var items = config.parameters.simpleItem;
							config.parameters.simpleItem = items.Append(sitem).ToArray();
						} else {
							if (config.parameters == null) {
								config.parameters = new global::onvif.services.ItemList();
							}
							config.parameters.simpleItem = new ItemList.SimpleItem[] { sitem };
						}
					} else {
						elem.IsEnabled = false;
						if (config.parameters.simpleItem.Contains(sitem)) {
							int count = config.parameters.simpleItem.Count();
							var arr = new ItemList.SimpleItem[count - 1];
							int cnt = 0;
							for (int i = 0; i < count; i++) {
								if (config.parameters.simpleItem[i] != sitem) {
									arr[cnt] = config.parameters.simpleItem[i];
									cnt++;
								}
							}
							config.parameters.simpleItem = arr;
						}
					}
				});
				StackPanel tmppanel = new StackPanel();
				tmppanel.Orientation = Orientation.Horizontal;
				tmppanel.Children.Add(elem);
				tmppanel.Children.Add(chBox);

				spanel.Children.Add(tmppanel);
			});

			return spanel;
		}
开发者ID:zzilla,项目名称:ONVIF-Device-Manager,代码行数:65,代码来源:XmlParserFactory.cs

示例2: GetValueEditor

		FrameworkElement GetValueEditor(elementDescr element) {
			FrameworkElement felem = null;

			switch (element.QName.Name) { 
				case "int":
					IntegerUpDown numUp = new IntegerUpDown();
					numUp.Margin = new Thickness(3);
					numUp.Increment = 1;
					numUp.VerticalAlignment = VerticalAlignment.Center;
					numUp.MinWidth = 50;
					numUp.CreateBinding(IntegerUpDown.ValueProperty, element, x => {
						int val = 0;
						int.TryParse(element.Value, out val);
						return val;
					}, (o, v) => {
						o.Value = v.ToString();
					});
					felem = numUp;
					break;
				case "float":
					DoubleUpDown doubleUp = new DoubleUpDown();
					doubleUp.CultureInfo = System.Globalization.CultureInfo.InvariantCulture;
					doubleUp.Margin = new Thickness(3);
					doubleUp.Increment = 0.01f;
					doubleUp.FormatString = "F3";
					doubleUp.VerticalAlignment = VerticalAlignment.Center;
					doubleUp.MinWidth = 50;
					doubleUp.CreateBinding(DoubleUpDown.ValueProperty, element, x => {
						float val = 0;
						//float.TryParse(element.Value, out val);
						try {
							val = XmlConvert.ToSingle(element.Value);
						}catch(Exception err){
							dbg.Error(err);
						}
						return val;
					}, (o, v) => {
						o.Value = XmlConvert.ToString(v);
					});
					felem = doubleUp;
					break;
				case "boolean":
					CheckBox chBox = new CheckBox();
					chBox.Margin = new Thickness(3);
					chBox.CreateBinding(CheckBox.IsCheckedProperty, element, x => {
						bool val = false;
						bool.TryParse(element.Value, out val);
						return val;
					}, (o, v) => {
						o.Value = v.ToString();
					});
					felem = chBox;
					break;
				default:
					TextBox tbox = new TextBox();
					tbox.Margin = new Thickness(3);
					tbox.CreateBinding(TextBox.TextProperty, element, x => x.Value, (o, v) => {
						o.Value = v;
					});
					tbox.MinWidth = 50;
					tbox.VerticalAlignment = System.Windows.VerticalAlignment.Center;
					felem = tbox;
					break;
			}
			return felem;
		}
开发者ID:zzilla,项目名称:ONVIF-Device-Manager,代码行数:66,代码来源:XmlParserFactory.cs


注:本文中的System.Windows.Controls.CheckBox.CreateBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。