protected override void OnRefresh() { HeliosPanel panel = Visual as HeliosPanel; if (panel != null) { _backgroundImage = ConfigManager.ImageManager.LoadImage(panel.BackgroundImage); _backgroundBrush = null; if (_backgroundImage != null) { _backgroundBrush = new ImageBrush(_backgroundImage); switch (panel.BackgroundAlignment) { case ImageAlignment.Centered: _backgroundBrush.Stretch = Stretch.None; _backgroundBrush.TileMode = TileMode.None; _backgroundBrush.Viewport = new Rect(0d, 0d, 1d, 1d); _backgroundBrush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox; break; case ImageAlignment.Stretched: _backgroundBrush.Stretch = Stretch.Fill; _backgroundBrush.TileMode = TileMode.None; _backgroundBrush.Viewport = new Rect(0d, 0d, 1d, 1d); _backgroundBrush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox; break; case ImageAlignment.Tiled: _backgroundBrush.Stretch = Stretch.None; _backgroundBrush.TileMode = TileMode.Tile; _backgroundBrush.Viewport = new Rect(0d, 0d, _backgroundImage.Width, _backgroundImage.Height); _backgroundBrush.ViewportUnits = BrushMappingMode.Absolute; break; } } _topBorderImage = ConfigManager.ImageManager.LoadImage(panel.TopBorderImage); _rightBorderImage = ConfigManager.ImageManager.LoadImage(panel.RightBorderImage); _bottomBorderImage = ConfigManager.ImageManager.LoadImage(panel.BottomBorderImage); _leftBorderImage = ConfigManager.ImageManager.LoadImage(panel.LeftBorderImage); _topLeftCornerImage = ConfigManager.ImageManager.LoadImage(panel.TopLeftCornerImage); _topRigthCornerImage = ConfigManager.ImageManager.LoadImage(panel.TopRightCornerImage); _bottomLeftCornerImage = ConfigManager.ImageManager.LoadImage(panel.BottomLeftCornerImage); _bottomRightCornerImage = ConfigManager.ImageManager.LoadImage(panel.BottomRightCornerImage); } }
protected override void OnRender(DrawingContext drawingContext) { HeliosPanel panel = Visual as HeliosPanel; if (panel != null) { double width = panel.Width; double height = panel.Height; // TODO Subtract top/left/bottom/right border sizes from background draw (this will allow for rounded transparent corners). if (panel.FillBackground) { drawingContext.DrawRectangle(new SolidColorBrush(panel.BackgroundColor), null, new Rect(0, 0, width, height)); } if (_backgroundBrush != null) { drawingContext.DrawRectangle(_backgroundBrush, null, new Rect(0, 0, width, height)); } if (panel.DrawBorder) { if (_topBorderImage != null) { drawingContext.DrawImage(_topBorderImage, new Rect(0, 0, width, _topBorderImage.Height)); } if (_rightBorderImage != null) { drawingContext.DrawImage(_rightBorderImage, new Rect(width - _rightBorderImage.Width, 0, _rightBorderImage.Width, height)); } if (_bottomBorderImage != null) { drawingContext.DrawImage(_bottomBorderImage, new Rect(0, height - _bottomBorderImage.Height, width, _bottomBorderImage.Height)); } if (_leftBorderImage != null) { drawingContext.DrawImage(_leftBorderImage, new Rect(0, 0, _leftBorderImage.Width, height)); } if (_topLeftCornerImage != null) { drawingContext.DrawImage(_topLeftCornerImage, new Rect(0, 0, _topLeftCornerImage.Width, _topLeftCornerImage.Height)); } if (_topRigthCornerImage != null) { drawingContext.DrawImage(_topRigthCornerImage, new Rect(width - _topRigthCornerImage.Width, 0, _topRigthCornerImage.Width, _topRigthCornerImage.Height)); } if (_bottomRightCornerImage != null) { drawingContext.DrawImage(_bottomRightCornerImage, new Rect(width - _bottomRightCornerImage.Width, height - _bottomRightCornerImage.Height, _bottomRightCornerImage.Width, _bottomRightCornerImage.Height)); } if (_bottomLeftCornerImage != null) { drawingContext.DrawImage(_bottomLeftCornerImage, new Rect(0, height - _bottomLeftCornerImage.Height, _bottomLeftCornerImage.Width, _bottomLeftCornerImage.Height)); } } } }