<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Veracity Solutions Blog &#187; itemcontainerstyle</title>
	<atom:link href="http://blogs.veracitysolutions.com/tag/itemcontainerstyle/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.veracitysolutions.com</link>
	<description>Software Consulting That Rocks</description>
	<lastBuildDate>Thu, 22 Apr 2010 17:21:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How Do I Style The ComboBox Items?</title>
		<link>http://blogs.veracitysolutions.com/how-do-i-style-the-combobox-items/</link>
		<comments>http://blogs.veracitysolutions.com/how-do-i-style-the-combobox-items/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 06:45:21 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Combobox]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[itemcontainerstyle]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[Triggers]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/02/07/how-do-i-style-the-combobox-items/</guid>
		<description><![CDATA[This is actually a continuation of my post on getting the ComboBox items to accept text wrapping, so I&#8217;ll be working from that point forward. If you&#8217;re coming fresh into this, you won&#8217;t be missing anything&#8230; but that is my explaination for the pictures containing wrapping text.
When last we left our heroes, we has a [...]]]></description>
			<content:encoded><![CDATA[<p>This is actually a continuation of my post on <a href="http://www.designerwpf.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/">getting the ComboBox items to accept text wrapping</a>, so I&#8217;ll be working from that point forward. If you&#8217;re coming fresh into this, you won&#8217;t be missing anything&#8230; but that is my explaination for the pictures containing wrapping text.</p>
<p>When last we left our heroes, we has a couple problems. The first was that our items were either black text on a white background and ran together in a very un-designer-y way.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/basicview.png" alt="BeginningViewComboStyling" /></p>
<p>The second was that the selected item background makes your eyes bleed such a horrid blue color you&#8217;ll feel like Paul Atreides staring at a stone burner.</p>
<p>Was that a little too geek? My apologies.</p>
<p><span id="more-236"></span></p>
<p>Anyway, let&#8217;s do something to make this control a little more usable (as well as easier on our eyes).</p>
<p>Highlight your ComboBox and go up to the toolbar, selecting <strong>Object -&gt; Edit Other Styles -&gt; Edit ItemContainerStyle -&gt; Edit a Copy…</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/itemcontainerstylemenu.png" alt="ItemContainerStyleMenuCombo" /></p>
<p>We&#8217;re now in the ItemContainerStyle editing mode. I really just need some demarcation between the items, so I&#8217;m going to give the items a BorderBush with a gradient that has a nice blue at the top and fades down to transparency at the bottom. It looks something like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/borderbrushgradient.png" alt="BorderBrushGradient" /></p>
<p>We will, of course, want our users to see this border, so let&#8217;s give the style a BorderThickness of 1 all around and a Margin of 4 to offer a little space. Our items now look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/stylework.png" alt="ComboboxItemsStylingWork" /></p>
<p>Better… but we don&#8217;t see the trigger for that hideous shade of blue in the style, so we need to go somewhere else to change it. Right click on the Style and go to <strong>Edit ControlParts (Template) -&gt; Edit Template</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/templatemenu.png" alt="TemplateMenu" /></p>
<p>We can see that the template here is exceedingly dull… just a border surrounding a ContentPresenter. We like dull. Dull means it&#8217;s not complex. First, let&#8217;s do some polishing up… give that border a CornerRadius of 5. Keep in mind that this is Vista-based development… no sharp corners allowed.</p>
<p>Now, let&#8217;s kill that blue. Click on the <strong>&#8220;IsHighlighted = True&#8221;</strong> trigger at the top…</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/ishighlightedtrigger.png" alt="IsHighlightedTrigger" /></p>
<p>..and we can see the highlighted state. I changed the Background to a nice soft blue gradient (you can change it to a deep purple with a green bubble for all I care… it&#8217;s WPF, go nuts!) This would be great except that I can&#8217;t see the Foreground now, so let&#8217;s change that to make the text readable.</p>
<p> I couldn&#8217;t figure out how to do this in the design mode, so find the IsHighlighted Trigger in the XAML and insert the bold text below:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Trigger</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">IsHighlighted</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">true</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Foreground</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">#FF001720</font>&#8220;<font color="#0000ff">/&gt;<br />
</font>      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Background</font>&#8221; <font color="#ff0000">TargetName</font>=&#8221;<font color="#0000ff">Bd</font>&#8220;<font color="#0000ff">&gt;<br />
      &#8230;</font></p>
<p>Now our ComboBox items look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/finalcomboboxitems.png" alt="FinalComboBoxItems" /></p>
<p>Much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-do-i-style-the-combobox-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The WPF Designers Guide to Styling The ComboBox</title>
		<link>http://blogs.veracitysolutions.com/the-wpf-designers-guide-to-styling-the-combobox/</link>
		<comments>http://blogs.veracitysolutions.com/the-wpf-designers-guide-to-styling-the-combobox/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 05:37:04 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Combobox]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Designer Guides]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[ContentPresenter]]></category>
		<category><![CDATA[itemcontainerstyle]]></category>
		<category><![CDATA[ItemsPresenter]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[WPF Designer Guide]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/02/07/the-wpf-designers-guide-to-styling-the-combobox/</guid>
		<description><![CDATA[ The ComboBox is not the most complex of the WPF applications, but it can be a little tricky, so lets do a general overview post of it before we go into the specifics of how we&#8217;re going to make it work.
First of all, if you&#8217;re going to test your comboBox design, you should have it [...]]]></description>
			<content:encoded><![CDATA[<p> The ComboBox is not the most complex of the WPF applications, but it can be a little tricky, so lets do a general overview post of it before we go into the specifics of how we&#8217;re going to make it work.</p>
<p>First of all, if you&#8217;re going to test your comboBox design, you should have it hooked up to an ItemsSource. Don&#8217;t have one? I have a tutorial in which I walk through <a href="http://www.designerwpf.com/2007/12/13/how-do-i-connect-an-rss-feed-to-my-listviewlistboxwhatever/">attaching an RSS feed to your control</a>. It was originally written for the ListView, but it will work fine for a ComboBox.</p>
<p>To start out&#8230; this is your standard ComboBox:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/unalteredcombobox.png" alt="unalteredComboBox" /></p>
<p>When working on a comboBox, you have a couple of options for the Items inside the ComboBox. If the options never change and are not data-driven, you can just toss come ComboBoxItems into it. Otherwise, you can connect it to some kind of ItemsSource (see the link above).</p>
<p>All of my examples are done with a data-driven ComboBoxes, but you should get the desired results if you run through the tutorials with ComboBoxItems.</p>
<p>First, a little bit about the structure of the comboBox.</p>
<p><span id="more-228"></span></p>
<p>The comboBox consists of a couple basic elements. The main part that you would normally click on is a ToggleButton. The information we can see is a ContentPresenter. When you open the ComboBox, you get a popup that is holding an ItemsPresenter.</p>
<p>The ComboBox is a little different inasmuch as it has both a ContentPresenter and an ItemsPresenter, which means that it can take in two different DataTemplates for these different presenters. (If all this is confusing to you, subscribe to my RSS feed… I&#8217;m working on a guide to Styles and Templates which will explain all this in detail.)</p>
<p>Anyway, in the spirit of <a href="http://www.designerwpf.com/2007/12/06/the-wpf-designers-guide-to-styling-the-your-favorite-adjectival-swear-word-here-listview/">my guide to the ListView</a>, I&#8217;m just going to spend the rest of the time guiding you through the basics of how to style the ComboBox. As I get to it, I&#8217;ll write the accompanying articles going into each in detail.</p>
<p><strong>Question 1:</strong> &#8220;How do I style the items in the dropdown?&#8221;</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/comboboxitems.png" alt="ComboItems" /></p>
<p><strong>Answer:</strong> Use the ItemContainerStyle and the accompanying template to define the look and feel of the items.</p>
<p><a href="http://www.designerwpf.com/2008/02/07/how-do-i-style-the-combobox-items/">How to edit the ComboBox ItemContainerStyle in Blend</a></p>
<p><strong>In the XAML:</strong></p>
<p>Put this in the resources:<br />
<font color="#0000ff">&lt;</font><font color="#800000">Style</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">MyComboItemStyle</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#cc9436">{x:Type ComboBoxItem}</font>&#8220;<font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Style</font><font color="#0000ff">&gt;</font></p>
<p>Put this in the composition:<br />
<font color="#0000ff">&lt;</font><font color="#800000">ComboBox</font><font color="#ff0000"> ItemContainerStyle</font>=&#8221;<font color="#cc9436">{DynamicResource MyComboItemStyle}</font>&#8221; <font color="#0000ff">/&gt;</font></p>
<p><strong>Question 2: </strong>&#8220;How do I change the look of the main ComboBox button (highlighted below)?&#8221;</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/comboboxtoggle.png" alt="ComboToggle" /></p>
<p><strong>Answer:</strong> Use the standard Style and Template properties.</p>
<p>How to Style the main ComboBox in Blend (coming soon).</p>
<p><strong>In the XAML:</strong></p>
<p>Put this in the resources:<br />
<font color="#0000ff">&lt;</font><font color="#800000">Style</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">MyComboStyle</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#cc9436">{x:Type ComboBox}</font>&#8220;<font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Style</font><font color="#0000ff">&gt;</font></p>
<p>Put this in the composition:<br />
<font color="#0000ff">&lt;</font><font color="#800000">ComboBox</font><font color="#ff0000"> Style</font>=&#8221;<font color="#cc9436">{DynamicResource MyComboStyle}</font>&#8221; <font color="#0000ff">/&gt;</font></p>
<p><strong>Question 3:</strong> &#8220;How do I style the ComboBox dropdown (highlighted below)?&#8221;</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/comboboxpopup.png" alt="ComboBoxPopup" /></p>
<p><strong>Answer:</strong> Go to the Popup control inside the ComboBox template.</p>
<p><a href="http://www.designerwpf.com/2008/03/24/styling-the-combobox-dropdown-popup/">How to style the ComboBox drop down in Blend.</a></p>
<p>In the XAML:</p>
<p>Put this in the resources:<br />
<font color="#0000ff">&lt;</font><font color="#800000">Style</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">MyComboStyle</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#cc9436">{x:Type ComboBox}</font>&#8220;<font color="#0000ff">&gt;<br />
      &lt;<font color="#800000">Setter</font><font color="#000000"> </font><font color="#ff0000">Property</font><font color="#000000">=&#8221;</font><font color="#0000ff">Template</font><font color="#000000">&#8220;</font></font><font color="#0000ff">&gt;<br />
            &lt;</font><font color="#800000">Setter.Value</font><font color="#0000ff">&gt;<br />
            &#8230;<br />
</font><font color="#0000ff">                  &lt;</font><font color="#800000">Popup</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">PART_Popup</font>&#8221; <font color="#0000ff">&gt;</font><br />
<font color="#0000ff"><font color="#008000"><font color="#0000ff">                        </font>&lt;!&#8211; Edit here &#8211;&gt;<br />
</font>                  &lt;/</font><font color="#800000">Popup</font><font color="#0000ff">&gt;<br />
            &#8230;<br />
</font><font color="#0000ff">            &lt;/</font><font color="#800000">Setter.Value</font><font color="#0000ff">&gt;<br />
      &lt;/<font color="#800000">Setter</font>&gt;<br />
</font><font color="#0000ff">&lt;/<font color="#800000">Style</font><font color="#0000ff">&gt;</font></font></p>
<p>Put this in the composition:<br />
<font color="#0000ff">&lt;</font><font color="#800000">ComboBox</font><font color="#ff0000"> Style</font>=&#8221;<font color="#cc9436">{DynamicResource MyComboStyle}</font>&#8221; <font color="#0000ff">/&gt;</font></p>
<p>There are, of course, other questions related to the ComboBox, but this is just the basics. I&#8217;ll look at some of the more intense ComboBox styling tasks in the near future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/the-wpf-designers-guide-to-styling-the-combobox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Styling ListView Items Using Blend</title>
		<link>http://blogs.veracitysolutions.com/styling-listview-items-using-blend/</link>
		<comments>http://blogs.veracitysolutions.com/styling-listview-items-using-blend/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 06:17:13 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[itemcontainerstyle]]></category>
		<category><![CDATA[items]]></category>
		<category><![CDATA[listviewitem template]]></category>
		<category><![CDATA[Styles]]></category>
		<category><![CDATA[Templates]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/01/15/styling-listview-items-using-blend/</guid>
		<description><![CDATA[So&#8230; you&#8217;ve got your listview and you want your items to look a certain way. In this post, we&#8217;ll look at changing as many things as we can inside the ListView ItemContainerStyle.
 First things first&#8230; getting to the ItemContainerStyle using Blend. With the ListView selected, go to the top menu and click:
 Edit Other Styles -&#62; Edit ItemContainerStyle [...]]]></description>
			<content:encoded><![CDATA[<p>So&#8230; you&#8217;ve got your listview and you want your items to look a certain way. In this post, we&#8217;ll look at changing as many things as we can inside the ListView ItemContainerStyle.</p>
<p> First things first&#8230; getting to the ItemContainerStyle using Blend. With the ListView selected, go to the top menu and click:</p>
<p> <strong>Edit Other Styles -&gt; Edit ItemContainerStyle -&gt; Create Empty&#8230;</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/itemcontainerstylemenu.png" alt="ItemContainerStyleMenu" /></p>
<p>Name your Style and you get tossed into Style editing. Here, you can do all sorts of great things, like&#8230; um&#8230; changing the background or something.</p>
<p><span id="more-131"></span></p>
<p> OK, I&#8217;ll fess up, I&#8217;ve found the ItemContainerStyle to be good for the following things (and not too much else):</p>
<ul>
<li>Giving your items a nice border.</li>
<li>Changing up and down margins (how far apart your  items are from one another)</li>
<li>Changing the HorizontalContentAlignment (<a href="http://www.designerwpf.com/2007/12/17/how-do-i-center-something-in-my-listview-column/">like in this post on centering items in a column</a>)</li>
<li>Changing the VerticalContentAlignment (if you have a thick item, you can get your data to align to the top or center or whatever)</li>
</ul>
<p>However, in order to get to the real fun stuff with ListView items, we want to go into the ItemContainerStyle template. So right-click on the &#8220;ItemContainerStyle&#8221; in your &#8220;Objects and Timeline&#8221; panel and go to:</p>
<p><strong>Edit Control Parts (Template) -&gt; Edit a Copy&#8230;</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/itemcontainerstyletemplate.png" alt="ItemContainerStyleTemplate" /></p>
<p>And now you have a copy of your default ListViewItemTemplate. If you want a good example of how a lookless control is constructed, head here. You&#8217;ll see how they use split grids and transparent gradients to get a look that maintains it&#8217;s feel even when the base background is changed. I&#8217;m working inside Vista, so this is what the visual tree of my ListViewItemTemplate looks like:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/listviewitemtemplatetree.png" alt="ListViewTemplateTree" /></p>
<p>But if you&#8217;re like me, what is interesting about this particular template is not the visual tree&#8230; it is the triggers that the template hands to you. Lets look at these triggers one by one.</p>
<p>(If you don&#8217;t know where the triggers are, they&#8217;re above the Objects and Timeline pane and they look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/listviewitemtemplateevents.png" alt="ItemEvents" /></p>
<p>Clicking on a trigger will give you a preview of what that trigger looks like and will also allow you to change the properties of anything inside the template that will implement when the trigger is active.</p>
<p>You <em>can</em> put these same triggers into your ItemContainerStyle and, as a general rule, I would recommend it. As a general rule, I would recommend putting as much into the style and staying out of the template for the sake of simplicity. However, the style does have some pretty significant limitations, especially in this case. So, for the meantime, we&#8217;re just going to futz with it as it has been given to us.)</p>
<p><strong>IsMouseOver = True</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/ismouseover.png" alt="IsMouseOver_ListViewItem" /></p>
<p>Kind of obvious what this does.</p>
<p><strong>IsSelected = True</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/isselected.png" alt="IsSelected_ListView" /></p>
<p>Again, kind of self-explanitory. When an item is selected, this is what you get.</p>
<p><strong>IsSelected = True and IsSelectionActive = False</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/isselected_isselectionactive.png" alt="IsSelected_IsSelectionActive" /></p>
<p>This is the default state of the first item in your listview before you&#8217;ve done anything to it. I have to admit, it took me quite some time to figure that out. The designers I was working with thought this style would confuse users and so we got rid of it. If you want to get rid of it, just delete this trigger and you&#8217;re golden.</p>
<p><strong>IsSelected = True and IsMouseOver = True</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/isselected_ismouseover.png" alt="IsSelected_IsMouseOver_ListView" /></p>
<p>In this example, it is subltly different than the IsMouseOver alone, but you can see the difference.</p>
<p><strong>IsEnabled = False</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/01/isenabled.png" alt="IsEnabled" /></p>
<p>I vaugely recall working on a project in which I tried to get individual items to unenable and I vaugely recall it not working very well. It could be because I was trying to do it in XAML, but the example you&#8217;re seeing here is when the entire ListView has IsEnabled set to &#8220;False&#8221;</p>
<p>A couple of suggestion for getting a good feel of the ItemContainerStyle triggers:</p>
<ul>
<li>change the background when the user selects an item</li>
<li>change the height when the user selects AND mouses over an item.</li>
<li>change the visibility to &#8220;Collapsed&#8221; when the user mouses over an item. (This one is sure to make your users roll on the floor with laughter&#8230; shortly before they come after you with torch and pitchfork in hand.)</li>
</ul>
<p>All of these triggers are property triggers, so they are not (as they stand) suitible for triggering any animations. If you&#8217;re interested in seeing animations in your ListView items, check out this post (coming soon).</p>
<p>If you&#8217;re more interested in what you can do with triggers, check out this post (coming soon).</p>
<p>If you&#8217;d like to have that nifty &#8220;every-other-item-is-gray&#8221; thing going on, <a href="http://www.beacosta.com/blog/?cat=9">here&#8217;s a post for you </a>while I try to whip up something of my own.</p>
<p>Please sound off with any more comments if you have additional questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/styling-listview-items-using-blend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Do I Center Something In My ListView Column?</title>
		<link>http://blogs.veracitysolutions.com/how-do-i-center-something-in-my-listview-column/</link>
		<comments>http://blogs.veracitysolutions.com/how-do-i-center-something-in-my-listview-column/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 20:09:26 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[celltemplate]]></category>
		<category><![CDATA[Column]]></category>
		<category><![CDATA[DataTemplate]]></category>
		<category><![CDATA[itemcontainerstyle]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2007/12/17/how-do-i-center-something-in-my-listview-column/</guid>
		<description><![CDATA[So the items in your ListView column look like this:

And you want them to look like this:

If you&#8217;re trying to center something within a ListView column, it&#8217;s actually pretty simple.

First, go to your ListView and, if you haven&#8217;t already, create an ItemContainerStyle by going to the Object -&#62; Edit Other Styles&#8230; -&#62; Edit ItemContainerStyle -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.designerwpf.com/wp-content/uploads/2007/12/centeredexample2.png" title="Centered Example 2"></a><a href="http://www.designerwpf.com/wp-content/uploads/2007/12/centeredexample1.png" title="Centered Example 1"></a><a href="http://www.designerwpf.com/wp-content/uploads/2007/12/itemcontainerstyle.png" title="ItemContainerStyle Menu"></a>So the items in your ListView column look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2007/12/centeredexample1.png" alt="Centered Example 1" /></p>
<p>And you want them to look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2007/12/centeredexample2.png" alt="Centered Example 2" /></p>
<p>If you&#8217;re trying to center something within a ListView column, it&#8217;s actually pretty simple.</p>
<p><span id="more-113"></span></p>
<p>First, go to your ListView and, if you haven&#8217;t already, create an ItemContainerStyle by going to the <strong>Object -&gt; Edit Other Styles&#8230; -&gt; Edit ItemContainerStyle -&gt; Create Empty&#8230;</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2007/12/itemcontainerstyle.png" alt="ItemContainerStyle Menu" /></p>
<p>Within your ItemContainerStyle, set the <font color="#ff0000">HorizontalContentAlignment</font> from &#8220;<font color="#0000ff">Left</font>&#8221; to &#8220;<font color="#0000ff">Stretch</font>&#8220;.</p>
<p>Your ItemContainerStyle XAML should now look like this (important stuff in bold):</p>
<p><font color="#0000ff">&lt;<font color="#800000">Style</font> <font color="#ff0000">x:Key</font><font color="#000000">=&#8221;</font>MyItemContainerStyle<font color="#000000">&#8220;</font> <font color="#ff0000">TargetType</font><font color="#000000">=&#8221;</font><font color="#b8860b">{x:Type ListViewItem}</font><font color="#000000">&#8220;</font>&gt;<br />
      <strong>&lt;<font color="#800000">Setter</font> <font color="#ff0000">Property</font><font color="#000000">=&#8221;</font>HorizontalContentAlignment<font color="#000000">&#8220;</font> <font color="#ff0000">Value</font><font color="#000000">=&#8221;</font>Stretch<font color="#000000">&#8220;</font>/&gt;</strong><br />
&lt;/<font color="#800000">Style</font>&gt;</font></p>
<p>A point of note: if you want everything to be centered, you can set it to &#8220;<font color="#0000ff">Center</font>&#8220;. However, if you prefer more control over the layout of your columns (as I do), set it to stretch.</p>
<p>Now, go to the DataTemplate for the column you want to center. (If you don&#8217;t know how to get to the DataTemplate or how to create one, you can <a href="http://www.designerwpf.com/2007/12/13/styling-a-listview-column-using-blend/">find that information here</a>. Just look for &#8220;DataTemplate&#8221;.)</p>
<p>Within the DataTemplate, align your bound item so that the <font color="#ff0000">HorizontalAlignment</font> is set to &#8220;<font color="#0000ff">Center</font>&#8220;.</p>
<p>Your DataTemplate should now look something like this (important stuff in bold):</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">DataTemplate</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">AuthorTemplate</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">TextBlock</font> <font color="#ff0000">Text</font>=&#8221;<font color="#b8860b">{Binding Mode=OneWay, XPath=author}</font>&#8221; <font color="#ff0000">FontSize</font>=&#8221;<font color="#0000ff">12</font>&#8221;  <strong><font color="#ff0000">HorizontalAlignment</font>=&#8221;<font color="#0000ff">Center</font>&#8220;</strong> <font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">DataTemplate</font><font color="#0000ff">&gt;</font></p>
<p>Finally, your ListView should already be set up, but just to double check, make sure that your ListView XAML looks something like this:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">ListView</font> <strong><font color="#ff0000">ItemContainerStyle</font>=&#8221;<font color="#b8860b">{DynamicResource MyItemContainerStyle}</font>&#8220;</strong> <font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">ListView.View</font><font color="#0000ff">&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">GridView</font><font color="#0000ff">&gt;<br />
</font>                  <font color="#0000ff">&lt;</font><font color="#800000">GridViewColumn</font> <strong><font color="#ff0000">CellTemplate</font>=&#8221;<font color="#b8860b">{DynamicResource AuthorTemplate}</font>&#8220;</strong> <font color="#ff0000">Header</font>=&#8221;<font color="#0000ff">Author</font>&#8220;<font color="#0000ff">/&gt;</font><br />
            <font color="#0000ff">&lt;/</font><font color="#800000">GridView</font><font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;/</font><font color="#800000">ListView.View</font><font color="#0000ff">&gt;<br />
</font><font color="#0000ff">&lt;/</font><font color="#800000">ListView</font><font color="#0000ff">&gt;</font></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-do-i-center-something-in-my-listview-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
