private static void RegisterBrush(LibraryDevice libraryDevice) { var imageSource = GetImageSource(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId); var brush = new ImageBrush(imageSource); brush.Freeze(); _brushes.Add(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId, brush); }
private static void RegisterImageSource(LibraryDevice libraryDevice) { var frameworkElement = DeviceControl.GetDefaultPicture(libraryDevice); frameworkElement.SnapsToDevicePixels = false; frameworkElement.Width = DesignerItem.DefaultPointSize; frameworkElement.Height = DesignerItem.DefaultPointSize; frameworkElement.Arrange(new Rect(new Size(frameworkElement.Width, frameworkElement.Height))); var imageSource = new RenderTargetBitmap(DesignerItem.DefaultPointSize, DesignerItem.DefaultPointSize, EnvironmentParameters.DpiX, EnvironmentParameters.DpiY, PixelFormats.Pbgra32); imageSource.Render(frameworkElement); imageSource.Freeze(); _imageSources.Add(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId, imageSource); }
private void RegisterImageSource(LibraryDevice libraryDevice) { if (libraryDevice == null) return; var frameworkElement = DeviceControl.GetDefaultPicture(libraryDevice); frameworkElement.Width = 100; frameworkElement.Height = 100; frameworkElement.Measure(new Size(frameworkElement.Width, frameworkElement.Height)); frameworkElement.Arrange(new Rect(new Size(frameworkElement.Width, frameworkElement.Height))); var imageSource = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Pbgra32); imageSource.Render(frameworkElement); //RenderOptions.SetCachingHint(imageSource, CachingHint.Cache); imageSource.Freeze(); _imageSources.Add(libraryDevice.DriverId, imageSource); }
public DeviceDetailsViewModel() { Title = "Добавить устройство"; Devices = new List<DeviceViewModel>(); foreach (var driver in FiresecManager.Drivers) { if (driver.IsPlaceable && !driver.IsIgnore && !FiresecManager.DeviceLibraryConfiguration.Devices.Any(x => x.DriverId == driver.UID)) { var libraryDevice = new LibraryDevice() { Driver = driver, DriverId = driver.UID }; var deviceViewModel = new DeviceViewModel(libraryDevice); Devices.Add(deviceViewModel); } } SelectedDevice = Devices.FirstOrDefault(); }
public DeviceViewModel(LibraryDevice libraryDevice) { LibraryDevice = libraryDevice; Driver = FiresecManager.Drivers.FirstOrDefault(x => x.UID == LibraryDevice.DriverId); if (Driver == null) { Driver = UnknownDeviceDriver; LibraryDevice.DriverId = Driver.UID; LibraryDevice.States = null; StateViewModels = new ObservableCollection<StateViewModel>(); } else { if (LibraryDevice.States == null) SetDefaultStateTo(LibraryDevice); StateViewModels = new ObservableCollection<StateViewModel>( LibraryDevice.States.Select(state => new StateViewModel(state, Driver)) ); } AddStateCommand = new RelayCommand(OnAddState); AddAdditionalStateCommand = new RelayCommand(OnAddAdditionalState); RemoveStateCommand = new RelayCommand(OnRemoveState, CanRemoveState); }
public static void SetDefaultStateTo(LibraryDevice device) { device.States = new List<LibraryState>(); device.States.Add(StateViewModel.GetDefaultStateWith()); }
public static LibraryDevice GetDefaultDriverWith(Guid driverId) { var device = new LibraryDevice(); device.DriverId = driverId; SetDefaultStateTo(device); return device; }
private static FrameworkElement GetDefaultPicture(LibraryDevice device) { var state = device.States.FirstOrDefault(x => x.Code == null && x.StateType == StateType.No); return state.Frames.Count > 0 ? Helper.GetVisual(state.Frames[0].Image) : EmptyPicture; }
private static void RegisterBrush(LibraryDevice libraryDevice) { var frameworkElement = libraryDevice == null ? EmptyPicture : GetDefaultPicture(libraryDevice); var brush = new VisualBrush(frameworkElement); if (_brushes.ContainsKey(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId)) _brushes[libraryDevice == null ? Guid.Empty : libraryDevice.DriverId] = brush; else _brushes.Add(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId, brush); }
public static FrameworkElement GetDefaultPicture(LibraryDevice device) { UIElement content = null; if (device != null) { var state = device.States.FirstOrDefault(x => x.Code == null && x.StateType == StateType.No); Canvas canvas = Helper.Xml2Canvas(state.Frames[0].Image); canvas.Background = Brushes.Transparent; content = canvas; } else content = new TextBlock() { Text = "?", Background = Brushes.Transparent }; var result = new Border() { BorderThickness = new Thickness(0), Background = Brushes.Transparent, Child = new Viewbox() { Child = content, } }; return result; }