public ParameterTemplateViewModel(XParameterTemplate parameterTemplate)
		{
			ParameterTemplate = parameterTemplate;
			DeviceParameterTemplates = new List<DeviceParameterTemplateViewModel>();
			foreach (var deviceParameterTemplate in parameterTemplate.DeviceParameterTemplates)
			{
				var deviceParameterTemplateViewModel = new DeviceParameterTemplateViewModel(deviceParameterTemplate);
				DeviceParameterTemplates.Add(deviceParameterTemplateViewModel);
			}
			SelectedDeviceParameterTemplate = DeviceParameterTemplates.FirstOrDefault();
		}
		void OnAdd()
		{
			var maxNo = XManager.ParameterTemplates.Max(x => x.No);
			var parameterTemplate = new XParameterTemplate()
			{
				Name = "Шаблон " + (maxNo + 1).ToString(),
				No = maxNo + 1
			};
			XManager.ParameterTemplates.Add(parameterTemplate);
			Invalidate();
			var parameterTemplateViewModel = new ParameterTemplateViewModel(parameterTemplate);
			ParameterTemplates.Add(parameterTemplateViewModel);
			SelectedParameterTemplate = parameterTemplateViewModel;
			ServiceFactory.SaveService.GKChanged = true;
		}
		static void CopyParametersFromTemplate(XParameterTemplate parameterTemplate, XDevice device)
		{
			var deviceParameterTemplate = parameterTemplate.DeviceParameterTemplates.FirstOrDefault(x => x.XDevice.DriverUID == device.Driver.UID);
			if (deviceParameterTemplate != null)
			{
				foreach (var property in deviceParameterTemplate.XDevice.Properties)
				{
					var deviceProperty = device.Properties.FirstOrDefault(x => x.Name == property.Name);
					if (deviceProperty != null)
					{
						deviceProperty.Value = property.Value;
					}
				}
			}
		}
		void Invalidate()
		{
			if (XManager.ParameterTemplates.Count == 0)
			{
				var parameterTemplate = new XParameterTemplate()
				{
					Name = "По умолчанию"
				};
				XManager.ParameterTemplates.Add(parameterTemplate);
			}

			foreach (var parameterTemplate in XManager.ParameterTemplates)
			{
				foreach (var deviceParameterTemplate in parameterTemplate.DeviceParameterTemplates)
				{
					deviceParameterTemplate.XDevice.Driver = XManager.Drivers.FirstOrDefault(x => x.UID == deviceParameterTemplate.XDevice.DriverUID);
				}
				parameterTemplate.DeviceParameterTemplates.RemoveAll(x => x.XDevice.Driver == null);

				foreach (var driver in XManager.Drivers)
				{
					if (driver.Properties.Any(x => x.IsAUParameter))
					{
						var deviceParameterTemplate = parameterTemplate.DeviceParameterTemplates.FirstOrDefault(x => x.XDevice.DriverUID == driver.UID);
						if (deviceParameterTemplate == null)
						{
							deviceParameterTemplate = new XDeviceParameterTemplate()
							{
								XDevice = new XDevice()
								{
									DriverUID = driver.UID,
									Driver = driver
								}
							};
							parameterTemplate.DeviceParameterTemplates.Add(deviceParameterTemplate);
						}

						var properties = new List<XProperty>();
						foreach (var driverProperty in driver.Properties)
						{
							if (driverProperty.IsAUParameter)
							{
								var property = deviceParameterTemplate.XDevice.Properties.FirstOrDefault(x => x.Name == driverProperty.Name);
								if (property == null || parameterTemplate.Name == "По умолчанию")
								{
									property = new XProperty()
									{
										Name = driverProperty.Name,
										Value = driverProperty.Default,
										DriverProperty = driverProperty
									};
									deviceParameterTemplate.XDevice.Properties.Add(property);
								}
								property.DriverProperty = driverProperty;
								properties.Add(property);
							}
						}
						deviceParameterTemplate.XDevice.Properties = properties;
					}
				}
			}
		}