/// <summary> /// Updates the view to match a new model. Updates event handlers and listeners. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CanvasHost_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var oldDc = e.OldValue as CanvasHostViewModel; if (oldDc != null) { oldDc.PropertyChanged -= ViewModelPropertyChanged; oldDc.Cells.CollectionChanged -= DrawOutline; oldDc.Leds.CollectionChanged -= DrawLed; oldDc.TouchRegions.CollectionChanged -= DrawTouchRegion; //oldDc.Frames.CollectionChanged -= DrawFrames; } _viewModel = e.NewValue as CanvasHostViewModel; ClearCanvas(); if (_viewModel == null) { return; } _viewModel.PropertyChanged += ViewModelPropertyChanged; _viewModel.Cells.CollectionChanged += DrawOutline; _viewModel.Leds.CollectionChanged += DrawLed; _viewModel.TouchRegions.CollectionChanged += DrawTouchRegion; // _viewModel.Frames.CollectionChanged += DrawFrames; UpdateImage(); }
public static ICanvasHostCommand Create(CanvasHostViewModel viewModel, CanvasHostMode mode) { switch (mode) { case CanvasHostMode.ColorFill: return(new FindCellCommand(viewModel)); case CanvasHostMode.PlaceLED: return(new PlaceLedCommand(viewModel)); case CanvasHostMode.CreateTouchRegion: return(new CreateTouchRegionCommand(viewModel)); case CanvasHostMode.PlaceLEDWithoutCell: return(new FindCellCommand(viewModel, System.Drawing.Color.FromArgb(0, 0, 0, 0))); //Transparent white case CanvasHostMode.None: default: return(null); } }
/// <summary> /// Constructor /// </summary> /// <param name="viewModel"></param> public CreateTouchRegionCommand(CanvasHostViewModel viewModel) { _viewModel = viewModel; }
public PlaceLedCommand(CanvasHostViewModel viewModel) { _viewModel = viewModel; }
public FindCellCommand(CanvasHostViewModel viewModel, System.Drawing.Color fillColor) : this(viewModel) { //Will fill the cell without asking for a color from the color dialog askForColor = false; this.fillColor = fillColor; }
public FindCellCommand(CanvasHostViewModel viewModel) { _viewModel = viewModel; }