void UserControl_Loaded(object sender, RoutedEventArgs e) { // if we're not in design mode, initialize the graphics device if (DesignerProperties.GetIsInDesignMode(this) == false && graphicsService == null) { // add a reference to the graphics device graphicsService = GraphicsDeviceService.AddRef((PresentationSource.FromVisual(this) as HwndSource).Handle); // create the image source imageSource = new RenderTargetImageSource(GraphicsDevice, (int)ActualWidth, (int)ActualHeight); rootImage.Source = imageSource.WriteableBitmap; // hook the rendering event CompositionTarget.Rendering += CompositionTarget_Rendering; // Invoke the ControlLoaded event if (ControlLoaded != null) { ControlLoaded(this, new GraphicsDeviceEventArgs(graphicsService.GraphicsDevice)); } } }
void UserControl_Loaded(object sender, RoutedEventArgs e) { // if we're not in design mode, initialize the graphics device if (DesignerProperties.GetIsInDesignMode(this) == false && graphicsService == null) { // add a reference to the graphics device graphicsService = GraphicsDeviceService.AddRef((PresentationSource.FromVisual(this) as HwndSource).Handle); // create the image source imageSource = new RenderTargetImageSource(GraphicsDevice, (int)ActualWidth, (int)ActualHeight); rootImage.Source = imageSource.WriteableBitmap; // hook the rendering event CompositionTarget.Rendering += CompositionTarget_Rendering; // Invoke the ControlLoaded event if (ControlLoaded != null) ControlLoaded(this, new GraphicsDeviceEventArgs(graphicsService.GraphicsDevice)); } }