<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ItemsControl: &#039;I&#039; is for Item Container</title>
	<atom:link href="http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/feed/" rel="self" type="application/rss+xml" />
	<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/</link>
	<description>Drinking (and serving) the WPF Kool-Aid since 2002</description>
	<lastBuildDate>Mon, 30 Aug 2010 18:54:01 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dr. WPF</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-2984</link>
		<dc:creator>Dr. WPF</dc:creator>
		<pubDate>Mon, 30 Aug 2010 18:54:01 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-2984</guid>
		<description>#Martin, I just tried the link and it worked for me.  Maybe the forums were down earlier.  Anyway, let me know if you continue to have trouble with the link and any specifics that might help me repro.  Thanks!</description>
		<content:encoded><![CDATA[<p>#Martin, I just tried the link and it worked for me.  Maybe the forums were down earlier.  Anyway, let me know if you continue to have trouble with the link and any specifics that might help me repro.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-2982</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Sat, 28 Aug 2010 08:31:08 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-2982</guid>
		<description>&quot;There are actually many different ways you can view these styles, as I describe in this forum post. &quot;

The link is dead.

These articles are great.</description>
		<content:encoded><![CDATA[<p>&#8220;There are actually many different ways you can view these styles, as I describe in this forum post. &#8221;</p>
<p>The link is dead.</p>
<p>These articles are great.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-2971</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Wed, 04 Aug 2010 14:34:04 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-2971</guid>
		<description>What if I wanted to be able to drag these characters around on the canvas and have their Locations change to reflect their position on the canvas?</description>
		<content:encoded><![CDATA[<p>What if I wanted to be able to drag these characters around on the canvas and have their Locations change to reflect their position on the canvas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nishant</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-841</link>
		<dc:creator>Nishant</dc:creator>
		<pubDate>Thu, 29 Apr 2010 18:06:16 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-841</guid>
		<description>Thank you Dr.

I realized what it exactly meant after some testing the next day. And I did go down the ItemContainerStyle route (which at the moment is working all right). 

The problem is that if you have Path/Line objects mixed with other UIElements , you cannot apply generic Canvas.Left/Canvas.Right logic. I ended up deriving from ListBox and ListBoxItem to handle this. It works but is not pretty. :D

Thanks again though. I would have never got the hang of this had it not been for your excellent post.

Cheers,
Nishant</description>
		<content:encoded><![CDATA[<p>Thank you Dr.</p>
<p>I realized what it exactly meant after some testing the next day. And I did go down the ItemContainerStyle route (which at the moment is working all right). </p>
<p>The problem is that if you have Path/Line objects mixed with other UIElements , you cannot apply generic Canvas.Left/Canvas.Right logic. I ended up deriving from ListBox and ListBoxItem to handle this. It works but is not pretty. <img src='http://drwpf.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Thanks again though. I would have never got the hang of this had it not been for your excellent post.</p>
<p>Cheers,<br />
Nishant</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr. WPF</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-830</link>
		<dc:creator>Dr. WPF</dc:creator>
		<pubDate>Tue, 27 Apr 2010 18:04:08 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-830</guid>
		<description>Hi Nishant,

If you are using a data template, then the item being added to the Items collection is *not* a UI element.  In your example, it is your TestItemVM object.

If you create an observable collection of UIElement objects, then those objects will become direct children of the items panel... they will *not* be wrapped in a ContentPresenter.  But, in my experience, there is rarely a good reason to maintain your own collection of UIElements.  It is much better to go with VM objects.

You can still use a Canvas as the ItemsPanel and use a binding on your ItemContainerStyle to set the appropriate Canvas.Left, Canvas.Top, etc, properties.

Hope this makes sense!

Cheers,
-dw</description>
		<content:encoded><![CDATA[<p>Hi Nishant,</p>
<p>If you are using a data template, then the item being added to the Items collection is *not* a UI element.  In your example, it is your TestItemVM object.</p>
<p>If you create an observable collection of UIElement objects, then those objects will become direct children of the items panel&#8230; they will *not* be wrapped in a ContentPresenter.  But, in my experience, there is rarely a good reason to maintain your own collection of UIElements.  It is much better to go with VM objects.</p>
<p>You can still use a Canvas as the ItemsPanel and use a binding on your ItemContainerStyle to set the appropriate Canvas.Left, Canvas.Top, etc, properties.</p>
<p>Hope this makes sense!</p>
<p>Cheers,<br />
-dw</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nishant</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-819</link>
		<dc:creator>Nishant</dc:creator>
		<pubDate>Mon, 26 Apr 2010 05:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-819</guid>
		<description>Hello Dr.,

Been reading up your posts for a while now and must mention that all your posts on WPF are exceptional.

Have a question with this one.

&quot;* If a UIElement is added to the Items collection of an explicit ItemsControl instance (as opposed to an instance of a derived class like ListBox), it will become a direct child of the items panel. If a non-UIElement is added, it will be wrapped within a ContentPresenter.&quot;

Does this also apply to UIElements instantiated with datatemplates and bound to the ItemsSource? I was under the impression thats the case but my test shows otherwise and it sucks because I thought it would give a ready to use ItemsSource property on a canvas.

    class TestItemVM : DependencyObject
    {
        string _text = &quot;test&quot;;
        public string Text 
        { 
            get { return _text; }
            set {  _text = value; }
        }
    }

    class TestVM : DependencyObject
    {
        public ObservableCollection Items 
        { 
            get 
            { 
                ObservableCollection items = new ObservableCollection();
                items.Add(new TestItemVM());
                return items ; 
            } 
        }
    }</description>
		<content:encoded><![CDATA[<p>Hello Dr.,</p>
<p>Been reading up your posts for a while now and must mention that all your posts on WPF are exceptional.</p>
<p>Have a question with this one.</p>
<p>&#8220;* If a UIElement is added to the Items collection of an explicit ItemsControl instance (as opposed to an instance of a derived class like ListBox), it will become a direct child of the items panel. If a non-UIElement is added, it will be wrapped within a ContentPresenter.&#8221;</p>
<p>Does this also apply to UIElements instantiated with datatemplates and bound to the ItemsSource? I was under the impression thats the case but my test shows otherwise and it sucks because I thought it would give a ready to use ItemsSource property on a canvas.</p>
<p>    class TestItemVM : DependencyObject<br />
    {<br />
        string _text = &#8220;test&#8221;;<br />
        public string Text<br />
        {<br />
            get { return _text; }<br />
            set {  _text = value; }<br />
        }<br />
    }</p>
<p>    class TestVM : DependencyObject<br />
    {<br />
        public ObservableCollection Items<br />
        {<br />
            get<br />
            {<br />
                ObservableCollection items = new ObservableCollection();<br />
                items.Add(new TestItemVM());<br />
                return items ;<br />
            }<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr. WPF</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-300</link>
		<dc:creator>Dr. WPF</dc:creator>
		<pubDate>Thu, 30 Apr 2009 01:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-300</guid>
		<description>Hi Michael,&lt;br&gt;&lt;br&gt;It&#039;s hard to say why its not working without seeing a repro. It probably has to do with the data against which you are binding. If its XML data, then try simply including a ContentPresenter without setting the Content property (the framework does funny stuff when binding against an xml source). Otherwise, you will need to debug the binding to see what is happening.&lt;br&gt;&lt;br&gt;If you have a simple repro, you can send it to me at ask[at]drwpf[dot]com.&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;-dw</description>
		<content:encoded><![CDATA[<p>Hi Michael,</p>
<p>It&#8217;s hard to say why its not working without seeing a repro. It probably has to do with the data against which you are binding. If its XML data, then try simply including a ContentPresenter without setting the Content property (the framework does funny stuff when binding against an xml source). Otherwise, you will need to debug the binding to see what is happening.</p>
<p>If you have a simple repro, you can send it to me at ask[at]drwpf[dot]com.</p>
<p>Cheers,<br />-dw</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-299</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Tue, 28 Apr 2009 16:55:32 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-299</guid>
		<description>Thanks for the post. I&#039;ve been trying to get this working with a databound itemscontrol. Within the itemscontainerstyle definition, I just have a border containing a contentpresenter. I have set the content to &quot;{Binding}&quot; but when i run the app, all i see is the border and not the item that should be hosted by the content presenter. Any thoughts as to where i&#039;m going wrong??</description>
		<content:encoded><![CDATA[<p>Thanks for the post. I&#8217;ve been trying to get this working with a databound itemscontrol. Within the itemscontainerstyle definition, I just have a border containing a contentpresenter. I have set the content to &#8220;{Binding}&#8221; but when i run the app, all i see is the border and not the item that should be hosted by the content presenter. Any thoughts as to where i&#8217;m going wrong??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Smyth</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-298</link>
		<dc:creator>Derek Smyth</dc:creator>
		<pubDate>Thu, 14 Aug 2008 03:59:08 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-298</guid>
		<description>What an excellent post Dr WPF. Thank you for taking the time to write it and for sharing.</description>
		<content:encoded><![CDATA[<p>What an excellent post Dr WPF. Thank you for taking the time to write it and for sharing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr. WPF</title>
		<link>http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-297</link>
		<dc:creator>Dr. WPF</dc:creator>
		<pubDate>Wed, 06 Aug 2008 00:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=32#comment-297</guid>
		<description>Hi Matt,&lt;br&gt;&lt;br&gt;The scenario described in that article arises because of a circular rooted reference.  This can happen, for example, when a child of a panel contains a binding whose source object is its parent and whose source property is the Children collection of that parent.  The problem is that the source property contains a rooted reference back to the child.  Normally, binding to the Children collection of a panel would not be a problem, but doing so from one of the actual children will create a problem, as described in the KB article.&lt;br&gt;&lt;br&gt;The best advice I can give on avoiding that scenario is to bind only to your view model objects, wherever possible.  Then the potential for this type of leak won&#039;t even arise.  Typically, the only time I use bindings to source objects that are not in the view model is when I&#039;m creating a control style or template.  For anything else, I will modify my view model to expose the required properties.&lt;br&gt;&lt;br&gt;Hope this helps!&lt;br&gt;-dw</description>
		<content:encoded><![CDATA[<p>Hi Matt,</p>
<p>The scenario described in that article arises because of a circular rooted reference.  This can happen, for example, when a child of a panel contains a binding whose source object is its parent and whose source property is the Children collection of that parent.  The problem is that the source property contains a rooted reference back to the child.  Normally, binding to the Children collection of a panel would not be a problem, but doing so from one of the actual children will create a problem, as described in the KB article.</p>
<p>The best advice I can give on avoiding that scenario is to bind only to your view model objects, wherever possible.  Then the potential for this type of leak won&#8217;t even arise.  Typically, the only time I use bindings to source objects that are not in the view model is when I&#8217;m creating a control style or template.  For anything else, I will modify my view model to expose the required properties.</p>
<p>Hope this helps!<br />-dw</p>
]]></content:encoded>
	</item>
</channel>
</rss>
