<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Fri, 24 May 2013 03:30:37 GMT</pubDate>
	<lastBuildDate>Fri, 24 May 2013 03:30:37 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>14</c9:totalResults>
	<c9:pageCount>-14</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>I am newbie to wpf and to this sort of programming in general. I have an example from Sams' WPF 4 Unleashed to which I am unable to set the background. I show it here greatly simplified and in VB.NET:</p><p><pre class="brush: text">Imports System.Windows
Imports System.Windows.Media
Imports System.Windows.Input

Namespace WTH
   Class Application
      &lt;STAThread()&gt; _
      Public Shared Sub Main()
         Dim whv As New WTH.WindowHostingVisual
         whv.ShowDialog()
      End Sub
   End Class

   Public Class WindowHostingVisual
      Inherits Window

      Private visuals As New List(Of Visual)()

      Public Sub New()
         Title = &quot;Hosting DrawingVisuals&quot;
         Width = 400
         Height = 400
         WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen
         Background = Brushes.Aquamarine
         Dim visLine As New DrawingVisual()
         Using dc As DrawingContext = visLine.RenderOpen()
            dc.DrawLine(New Pen(Brushes.White, 5), New Point(50, 200), New Point(350, 200))
            dc.PushOpacity(0.5)
         End Using
         visuals.Add(visLine)
      End Sub

      Protected Overrides ReadOnly Property VisualChildrenCount() As Integer
         Get
            Return visuals.Count
         End Get
      End Property

      Protected Overrides Function GetVisualChild(index As Integer) As Visual
         If index &lt; 0 OrElse index &gt;= visuals.Count Then
            Throw New ArgumentOutOfRangeException(&quot;index&quot;)
         End If
         Return visuals(index)
      End Function

   End Class
End Namespace</pre></p><p>Using XAML is what I want to avoid. Otherwise, what's the point of programming if I can't change things when and as I want. When I use the standard files created Automatically by VS 2010 Express for WPF, I can change the background just fine through the Window or the Grid. Here is the empty XAML version I am using now:</p><p><pre class="brush: text">&lt;Application x:Class=&quot;Application&quot;
    xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http&#58;&#47;&#47;schemas.microsoft.com&#47;winfx&#47;2006&#47;xaml&#47;presentation&#34;</a>
    xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;>">http&#58;&#47;&#47;schemas.microsoft.com&#47;winfx&#47;2006&#47;xaml&#34;&#62;</a>
    &lt;Application.Resources&gt;
        
    &lt;/Application.Resources&gt;
&lt;/Application&gt;</pre></p><p>When I comment out the two overrides in my code, the background changes, but nothing is drawn.</p><p>I have tried everything, so please save me from suicide.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/28cf4528c40f4c2197789efd01490161#28cf4528c40f4c2197789efd01490161</link>
		<pubDate>Thu, 09 Jun 2011 19:57:52 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/28cf4528c40f4c2197789efd01490161#28cf4528c40f4c2197789efd01490161</guid>
		<dc:creator>Dioniz</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dioniz/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>The background is not magical, it is drawn by the window. If you replace the visual content of the windows like this, there will be no background unless you draw it yourself.</p><p>You could add something like this</p><p>dc.DrawRectangle(Background, Nothing, New Rect(0, 0, Width, Height))</p><p>do your drawing code.&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/d9bc6d2e82c74ac6b56d9efe00a7a2a5#d9bc6d2e82c74ac6b56d9efe00a7a2a5</link>
		<pubDate>Fri, 10 Jun 2011 10:10:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/d9bc6d2e82c74ac6b56d9efe00a7a2a5#d9bc6d2e82c74ac6b56d9efe00a7a2a5</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>Whew! Thanks dex. Actually I wasn't going to do anything drastic.<br><br>&nbsp;I put the background on first to give it the lowest Z order and then pass over it in the hit testing. Here is the complete code for the sake of public documentation; it draw some scary ghost:</p><p><pre class="brush: vb">Imports System.Windows
Imports System.Windows.Media
Imports System.Collections.Generic
Imports System.Windows.Input

Namespace WindowHostingVisual
   Class Application
      &lt;STAThread()&gt; _
      Public Shared Sub Main()
         Dim whv As New WindowHostingVisual.WindowHostingVisual()
         whv.ShowDialog()
      End Sub
   End Class

   Namespace WindowHostingVisual
      Public Class WindowHostingVisual
         Inherits Window

         Private visuals As New List(Of Visual)()

         Public Sub New()
            Title = &quot;Hosting DrawingVisuals&quot;
            Width = 400
            Height = 400
            Background = Brushes.Aquamarine
            Me.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen

            Dim bodyVisual As New DrawingVisual()
            Dim eyesVisual As New DrawingVisual()
            Dim mouthVisual As New DrawingVisual()
            Dim visBackground As New DrawingVisual

            Using dc As DrawingContext = bodyVisual.RenderOpen()
               dc.DrawGeometry(Brushes.Blue, Nothing, Geometry.Parse(&quot;M 240,250 C 200,375 200,250 175,200 C 100,400 100,250 100,200 C 0,350 0,250 30,130 C 75,0 100,0 150,0 C 200,0 250,0 250,150 Z&quot;))
            End Using

            Using dc As DrawingContext = eyesVisual.RenderOpen()
               dc.DrawEllipse(Brushes.Black, New Pen(Brushes.White, 10), New Point(95, 95), 15, 15)
               dc.DrawEllipse(Brushes.Black, New Pen(Brushes.White, 10), New Point(170, 105), 15, 15)
            End Using

            Using dc As DrawingContext = mouthVisual.RenderOpen()
               Dim p As New Pen(Brushes.Black, 10)
               p.StartLineCap = PenLineCap.Round
               p.EndLineCap = PenLineCap.Round
               dc.DrawLine(p, New Point(75, 160), New Point(175, 150))
            End Using

            Using dc As DrawingContext = visBackground.RenderOpen
               dc.DrawRectangle(Background, Nothing, New Rect(0, 0, Width, Height))
            End Using

            visuals.Add(visBackground)
            visuals.Add(bodyVisual)
            visuals.Add(eyesVisual)
            visuals.Add(mouthVisual)

            ' Bookkeeping:
            For Each v As Visual In visuals
               AddVisualChild(v)
               AddLogicalChild(v)
            Next

         End Sub

         ' The two necessary overrides, implemented for the single Visual:
         Protected Overrides ReadOnly Property VisualChildrenCount() As Integer
            Get
               Return visuals.Count
            End Get
         End Property

         Protected Overrides Function GetVisualChild(index As Integer) As Visual
            If index &lt; 0 OrElse index &gt;= visuals.Count Then
               Throw New ArgumentOutOfRangeException(&quot;index&quot;)
            End If
            Return visuals(index)
         End Function

         Protected Overrides Sub OnMouseLeftButtonDown(e As MouseButtonEventArgs)
            ' Rotate object clicked on.

            MyBase.OnMouseLeftButtonDown(e)
            ' Retrieve the mouse pointer location relative to the Window
            Dim location As Point = e.GetPosition(Me)
            ' Perform visual hit testing
            Dim result As HitTestResult = VisualTreeHelper.HitTest(Me, location)
            ' If we hit any DrawingVisual, rotate it
            If result.VisualHit.[GetType]() = GetType(DrawingVisual) Then
               Dim dv As DrawingVisual = TryCast(result.VisualHit, DrawingVisual)
               ' Don't rotate background.
               If dv.Equals(visuals.Item(0)) Then
                  Exit Sub
               End If
               If dv.Transform Is Nothing Then
                  dv.Transform = New RotateTransform()
               End If
               TryCast(dv.Transform, RotateTransform).Angle &#43;= 1
            End If
         End Sub
      End Class
   End Namespace
End Namespace
</pre></p><p>I think my real question is what I am really drawing on. It seems to not be the window object. I don't know what the DrawingContext actually is and where it fits in. I do now know the drawn objects can be accessed through LogicalTreeHelper and VisualTreeHelper. To quote from WPF Unleashed: &quot;However, you can easily traverse both the logical and visual trees using the somewhat<br>symmetrical System.Windows.LogicalTreeHelper and System.Windows.Media.<br>VisualTreeHelper classes.&quot;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/5c0cbd03b4b44fcfb6919efe012ffa02#5c0cbd03b4b44fcfb6919efe012ffa02</link>
		<pubDate>Fri, 10 Jun 2011 18:26:44 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/5c0cbd03b4b44fcfb6919efe012ffa02#5c0cbd03b4b44fcfb6919efe012ffa02</guid>
		<dc:creator>Dioniz</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dioniz/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p><blockquote><div class="quoteText">I think my real question is what I am really drawing on. It seems to not be the window object. I don't know what the DrawingContext actually is and where it fits in</div></blockquote></p><p>Well, yes, you're not drawing on the window but on those drawing visuals and they are the children (in the visual tree) of the window. DrawingContext stores the drawing commands and then it&nbsp;is closed (by means of using in this case) the stored commands become the content of the visual. Note that these drawing commands are not part of either the visual or logical tree.</p><p>It's also possible to draw directly&nbsp;on the window in the OnRender method but you need to set the window's template to an empty ControlTemplate, otherwise the template will show on top of your drawing and you won't see anything.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/425d2fdfd90f47d8b0589eff005d436f#425d2fdfd90f47d8b0589eff005d436f</link>
		<pubDate>Sat, 11 Jun 2011 05:39:33 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/425d2fdfd90f47d8b0589eff005d436f#425d2fdfd90f47d8b0589eff005d436f</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>I'm learning a lot, My program now toggles between full screen and normal. The background dimensions are set like this:</p><p><pre class="brush: vb"> dc.DrawRectangle(Brushes.White, Nothing, New Rect(0, 0, System.Windows.SystemParameters.FullPrimaryScreenWidth, System.Windows.SystemParameters.FullPrimaryScreenHeight))</pre></p><p>so the background always appears to completely cover the window.</p><p>But have a new question related to this. I want to be able to remove an object clicked on, or, change its position. I want to move it without having to remove it and redraw. I also need to know some positioning properties of the visual: x, y,height, width. Using dv in the key event: - dv.Offset.X and Y- just give me zeros, not the relative position. Google isn't helping me much here.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/0aaa3fb248544abea7419eff00c097a2#0aaa3fb248544abea7419eff00c097a2</link>
		<pubDate>Sat, 11 Jun 2011 11:41:12 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/0aaa3fb248544abea7419eff00c097a2#0aaa3fb248544abea7419eff00c097a2</guid>
		<dc:creator>Dioniz</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dioniz/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p><blockquote><div class="quoteText">Using dv in the key event: - dv.Offset.X and Y- just give me zeros, not the relative position</div></blockquote></p><p>Have you tried actually setting the offset? Initially the offset is 0 so no wonder you get zeroes...</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/a2f1822d4225456699ee9f0000699d03#a2f1822d4225456699ee9f0000699d03</link>
		<pubDate>Sun, 12 Jun 2011 06:24:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/a2f1822d4225456699ee9f0000699d03#a2f1822d4225456699ee9f0000699d03</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>Thanks. This is progress. I can now move things around after clicking on them It is a bit odd that I can move an element by setting its Offset but it doesn't know what offset originally was. My code now sets the Offset property of the DrawingVisual when&nbsp; created and reads it when clicked on. (BTW, the property has to be set by giving it &quot;New Vector(10, 10)&quot; or with whatever values. Otherwise you get &quot;expression is a value and therefore cannot be the target of an assignment&quot; when setting its x and y, even though they are read/write. Forgive for being confused.)<br><br>Again, though, I may have not asked the right question. If I click on a rectangle, is there a way to get the 'System.Windows.Media.RectangleGeometry' out of the DrawingVisual? Can reach its Rect and pen or brush without removing them and recreating them? And I still haven't figured out how to remove objects.<br><br>DrawingContext can draw a Ellipse, Geometry, GlyphRun, Line, and Rectangle, by using DrawDrawing, DrawEllipse, etc. This question goes for all of these.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/ddb462ecb430414db3e79f000154e147#ddb462ecb430414db3e79f000154e147</link>
		<pubDate>Sun, 12 Jun 2011 20:41:06 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/ddb462ecb430414db3e79f000154e147#ddb462ecb430414db3e79f000154e147</guid>
		<dc:creator>Dioniz</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dioniz/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p><blockquote><div class="quoteText">I can move an element by setting its Offset but it doesn't know what offset originally was</div></blockquote></p><p>Of course it know, the original offset is 0. You haven't set the offset when you created the visuals, why would it be anything else?</p><p><blockquote><div class="quoteText">If I click on a rectangle, is there a way to get the 'System.Windows.Media.RectangleGeometry' out of the DrawingVisual?</div></blockquote></p><p>Sort of. A DrawingVisual has a Drawing property of type DrawingGroup. This has a Children property and you can go through all the children and on children of type GeometryDrawing you have a Geometry property. The Geometry object has a number of methods that can be used for hit testing.</p><p><blockquote><div class="quoteText">Can reach its Rect and pen or brush without removing them and recreating them?</div></blockquote></p><p>Nope, those are read only. But you can do things a bit differently. Start by creating the needed geometries, for example 2 EllipseGeometry. Then draw them on the drawing context by using DrawGeometry instead of DrawEllipse. Now you can modify the properties of those geometries, for example you can apply a transform to them.</p><p><blockquote><div class="quoteText">And I still haven't figured out how to remove objects.</div></blockquote></p><p>Nope but the above &quot;tweak&quot; applies here to. You can start by creating the necessary geometries, put them all in a DrawingGroup object and the draw the drawing group on the drawing context by using DrawDrawing. Something like this:<br><pre class="brush: vb">Dim s As New DrawingVisual()

Dim rg As New RectangleGeometry(new Rect(0, 0, 100, 100))
Dim rgd As New GeometryDrawing(Brushes.Pink, Nothing, rg)

Dim dg As New DrawingGroup()
dg.Children.Add(rgd)

Using dc As DrawingContext = s.RenderOpen()
    dc.DrawDrawing(dg)

rgd.Brush = Brushes.Yellow
rg.Transform = new RotateTransform(42)
dg.Children.Remove(rgd)
</pre></p><p>But now the question raises, why don't you simply use a Canvas and some shapes?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/b95ad0e96423475d9ba99f01007b5fc5#b95ad0e96423475d9ba99f01007b5fc5</link>
		<pubDate>Mon, 13 Jun 2011 07:29:11 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/b95ad0e96423475d9ba99f01007b5fc5#b95ad0e96423475d9ba99f01007b5fc5</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>MSDN has pretty extensive documentation on using DrawingVisual, including hit testing:</p><p><a href="http://msdn.microsoft.com/en-us/library/ms742254.aspx#Y2113">http://msdn.microsoft.com/en-us/library/ms742254.aspx#Y2113</a></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/f8130bbca39149068bbc9f0100c50630#f8130bbca39149068bbc9f0100c50630</link>
		<pubDate>Mon, 13 Jun 2011 11:57:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/f8130bbca39149068bbc9f0100c50630#f8130bbca39149068bbc9f0100c50630</guid>
		<dc:creator>AndyC</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/AndyC/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>That sample hit tests visuals as a whole, it doesn't return the geometry inside the visual. Perhaps this is a more appropiate sample: <a href="http://msdn.microsoft.com/en-us/library/ms750584.aspx">http://msdn.microsoft.com/en-us/library/ms750584.aspx</a></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/9fb06e2a36dc4ea194a59f0100e20269#9fb06e2a36dc4ea194a59f0100e20269</link>
		<pubDate>Mon, 13 Jun 2011 13:42:52 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/9fb06e2a36dc4ea194a59f0100e20269#9fb06e2a36dc4ea194a59f0100e20269</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p><blockquote><div class="quoteText">But now the question raises, why don't you simply use a Canvas and some shapes?</div></blockquote></p><p>I should have said at the beginning. Shapes are said to be slower than visuals and I will have up to thousands of little object, so speed is important.</p><p>I didn't have time today to try your suggestions. This problem seems rather burning. Google searches are bringing next to nothing, and are including this thread already. Someone solved it by drawing the background on top of his object, a cop-out if there ever was one, but maybe the only solution. If I get this solved, I'll post the whole solution for others to follow. It'd sure be nice of someone from Microsoft chimed in about now, since this is their site.</p><p>Are EllipseGeometry, RectangleGeometry, and the like shapes or drawingvisuals? And what does it matter if I use a canvas or not? Sorry if these seem like dumb questions.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/8480e156c73d4ce48c4e9f010159d035#8480e156c73d4ce48c4e9f010159d035</link>
		<pubDate>Mon, 13 Jun 2011 20:59:04 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/8480e156c73d4ce48c4e9f010159d035#8480e156c73d4ce48c4e9f010159d035</guid>
		<dc:creator>Dioniz</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dioniz/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p><blockquote><div class="quoteText"></p><p><a class="permalink" title="Post Permalink" href="/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/8480e156c73d4ce48c4e9f010159d035">30 minutes&nbsp;ago</a>, <a href="/Niners/Acamapichtli">Acamapichtli</a> wrote</p><p>*snip*</p><p>I should have said at the beginning. Shapes are said to be slower than visuals and I will have up to thousands of little object, so speed is important.</p><p></div></blockquote></p><p>They're slower because they support all the necessary functionality for eventing and easily modifying them, for moving or changing individual shapes etc. If you implement all that on top of Visuals for your apps needs, you'll likely end up with something even slower (since it won't have all the low-level optimisations that WPF can provide).</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/db7c3888532842cdb1a19f0101631966#db7c3888532842cdb1a19f0101631966</link>
		<pubDate>Mon, 13 Jun 2011 21:32:52 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/db7c3888532842cdb1a19f0101631966#db7c3888532842cdb1a19f0101631966</guid>
		<dc:creator>AndyC</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/AndyC/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p><blockquote><div class="quoteText">Are EllipseGeometry, RectangleGeometry, and the like shapes or drawingvisuals?</div></blockquote></p><p>Geometries are basically drawing commands which are executed by visuals, they aren't visuals themselfs. Shapes are visuals that contain only one geometry.</p><p><blockquote><div class="quoteText">And what does it matter if I use a canvas or not?</div></blockquote></p><p>Well, I'd say a canvas is simpler to use. And as AndyC said already, since you have to reimplement a number of things like hit testing, how do you know if your approach will be faster in the end? A quick test I did shows the following:</p><ul><li>1000 ellipses - both approaches render fast, the window resizes smoothly </li><li>10000 ellipses - things starts to be slugish... in both cases </li><li>100000 ellipses - ok, this means trouble... again, in both cases. Some profiling shows that &gt;70% of CPU time is spent in milcore and the video driver, both are native components, they have no idea that you used a canvas or not. </li></ul><p>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/d403a362210248fba73a9f0200703806#d403a362210248fba73a9f0200703806</link>
		<pubDate>Tue, 14 Jun 2011 06:48:34 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/d403a362210248fba73a9f0200703806#d403a362210248fba73a9f0200703806</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - I always get a black backgraound with DrawingContext in WPF</title>
		<description><![CDATA[<p>I SOLVED IT !!! here is the event handler:</p><p><pre class="brush: vb">   Protected Overrides Sub OnMouseLeftButtonDown(e As MouseButtonEventArgs)
      MyBase.OnMouseLeftButtonDown(e)
      Dim location As Point = e.GetPosition(Me)
      Dim result As HitTestResult = VisualTreeHelper.HitTest(Me, location)
      Dim hitVisual As DrawingVisual = TryCast(result.VisualHit, DrawingVisual)
      If result.VisualHit.[GetType]() = GetType(DrawingVisual) And Not hitVisual.Equals(visBackground) Then
         visuals.Remove(hitVisual)
         RemoveVisualChild(hitVisual)
         RemoveLogicalChild(hitVisual)
      End If
   End Sub</pre></p><p>Duh: RemoveVisualChild and RemoveLogicalChild. I test for the background to prevent it being deleted. If I want to change the color or other feature of the object, I can delete it and draw again. I don't think the deletion could be noticed. I am working on a generalized example to post. Thanks for helping me on this. Dexter, I'm glad you did that test. Ill have to play around more with this.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/5f024a826961468f8f749f020128cdc2#5f024a826961468f8f749f020128cdc2</link>
		<pubDate>Tue, 14 Jun 2011 18:00:37 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/I-always-get-a-black-backgraound-with-DrawingContext-in-WPF/5f024a826961468f8f749f020128cdc2#5f024a826961468f8f749f020128cdc2</guid>
		<dc:creator>Dioniz</dc:creator>
		<slash:comments>14</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dioniz/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>