private void SetPreviewImage(LayoutImage image, string source) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.UriSource = new Uri(source); bi.EndInit(); image.Source = bi; }
private void listImages_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (m_layoutCanvas == null || listImages.SelectedIndex < 0 || m_isManuallyEditing) return; string source = ((ImageBrowserPreview)listImages.SelectedItem).FilePath; UIElement elem = canvas.SelectedElement; bool canAdd = (elem == null) && m_layoutCanvas.SingleObjectStyle == PlacementStyle.Custom; if (m_layoutCanvas.Count == 0 || canAdd) { // If we have ABSOLUTELY NOTHING, OR WE WANT TO ADD, DO THIS SimpleImageObject sio = new SimpleImageObject(source); LayoutImage lImage = new LayoutImage(sio); m_layoutCanvas.Add(sio); lImage.Width = sio.SourceWidth; lImage.Height = sio.SourceHeight; canvas.AddChild(lImage); SetPreviewImage(lImage, sio.Source); if (cmbFillMode.SelectedIndex != 4) { ApplyQuickLayout(sio, (PlacementStyle)cmbFillMode.SelectedIndex); } else { sio.ActualWidth = sio.SourceWidth; sio.ActualHeight = sio.SourceHeight; sio.X = 0; sio.Y = 0; } RefreshCanvasChild(lImage); RefreshFillModeState(); RefreshAdvancedButtonState(); } else { // EDIT THE SELECTED ELEMENT, OR FIRST ELEMENT if (elem == null) elem = canvas.First(); SimpleImageObject sio = (SimpleImageObject)((LayoutImage)elem).LayoutObject; sio.Source = source; // We have a selected element, modify it SetPreviewImage((LayoutImage)elem, sio.Source); if (cmbFillMode.SelectedIndex != 4) { ApplyQuickLayout(sio, (PlacementStyle)cmbFillMode.SelectedIndex); RefreshCanvasChild((LayoutImage)elem); } } }
private void RefreshCanvasChild(LayoutImage elem) { LayoutObject lo = ((LayoutImage)elem).LayoutObject; canvas.MoveUIElement(elem, new Point(lo.X, lo.Y), DraggableCanvas.MeasureType.Absolute); canvas.ResizeUIElement(elem, new Size(lo.ActualWidth, lo.ActualHeight), DraggableCanvas.MeasureType.Absolute); canvas.FlipUIElement(elem, lo.IsFlippedX, lo.IsFlippedY); canvas.SetUIElementZIndex(elem, lo.Z); }
public void SetupLayout(LayoutCanvas layoutCanvas, Screen screen, bool isDesktopMode) { // Cache the references to the canvas and screen m_layoutCanvas = layoutCanvas; m_screen = screen; // Set initial canvas attributes canvas.Width = screen.Width; canvas.Height = screen.Height; // Set the canvas background canvas.Background = new SolidColorBrush( WpfToGdi.GdiColorToWpfColour(layoutCanvas.BackgroundColour)); canvas.ClearChildren(); foreach (LayoutObject lo in layoutCanvas) { LayoutImage lImage = new LayoutImage(lo); // Add to canvas (but don't add through the helper, because we want to manually manipulate // this object) canvas.Children.Add(lImage); // Set the preview image SetPreviewImage(lImage, lo.Source); // Set attributes onto the child RefreshCanvasChild(lImage); } // Set the manual edit flag so that we don't trigger events when we change // these objects m_isManuallyEditing = true; chkShuffle.Visibility = isDesktopMode ? Visibility.Visible : Visibility.Hidden; chkShuffle.IsChecked = layoutCanvas.IsShuffleEnabled; cmdChangeInterval.SelectedIndex = GetIntervalIndex(m_layoutCanvas.ShuffleMode); cmbFillMode.SelectedIndex = (int)m_layoutCanvas.SingleObjectStyle; m_isManuallyEditing = false; RefreshFillModeState(); RefreshAdvancedButtonState(); RefreshEditorState(); }