<?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>Designer Silverlight &#187; combobox</title>
	<atom:link href="http://www.designersilverlight.com/category/combobox/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.designersilverlight.com</link>
	<description>Matthias Shapiro's Silverlight &#38; WPF Blog - Because Developers Get All The Good Blogs</description>
	<lastBuildDate>Thu, 26 Jan 2012 06:45:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How To Use a ListView or DataGrid In a ComboBox Drop Down (Without A Line Of Code)</title>
		<link>http://www.designersilverlight.com/2008/10/01/how-to-use-a-listview-or-datagrid-in-a-combobox-drop-down-without-a-line-of-code/</link>
		<comments>http://www.designersilverlight.com/2008/10/01/how-to-use-a-listview-or-datagrid-in-a-combobox-drop-down-without-a-line-of-code/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 00:30:00 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[combobox]]></category>
		<category><![CDATA[listview]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2008/10/01/how-to-use-a-listview-or-datagrid-in-a-combobox-drop-down-without-a-line-of-code/</guid>
		<description><![CDATA[Super cool new thing I learned today. In WPF, we can make it so that the drop down (popup) on a ComboBox displays the data in a ListView. Because of the fact that I believe the DataGrid will eventually overtake the ListView as the gold standard for data display in WPF, we’ll do it both [...]]]></description>
			<content:encoded><![CDATA[<p>Super cool new thing I learned today. In WPF, we can make it so that the drop down (popup) on a ComboBox displays the data in a ListView. Because of the fact that I believe the DataGrid will eventually overtake the ListView as the gold standard for data display in WPF, we’ll do it both ways.</p>
<p>This tutorial is done entirely in Blend and without a line of code.</p>
<p><strong>Step 0)</strong> (for the DataGrid only)</p>
<p>Go to Code Plex and <a href="http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=14963">download the WPF Toolkit</a>. Extract to a convenient location.</p>
<p>Right-Click on the References folder in your project tab and click “Add Reference…”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image001.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image001-thumb.png" title="clip_image001" style="border-width: 0px; display: inline" alt="clip_image001" border="0" height="85" width="238" /></a></p>
<p>Navigate to the location you extracted the WPFToolkit.dll file, select it and hit OK.<br />
<a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0016.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0016-thumb.png" title="clip_image001[6]" style="border-width: 0px; display: inline" alt="clip_image001[6]" border="0" height="205" width="177" /></a></p>
<p>Step 1) Select the ComboBox you wish to change and edit the ControlTemplate by right-clicking and selecting “Edit Control Parts (Template) –&gt; Edit a Copy…”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0011.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0011-thumb.png" title="clip_image001[1]" style="border: 0px none ; display: inline" alt="clip_image001[1]" border="0" height="55" width="328" /></a></p>
<p>Step 2) Find the ItemsPresenter. This is what would normally display our ItemsSource.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0013.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0013-thumb.png" title="clip_image001[3]" style="border: 0px none ; display: inline" alt="clip_image001[3]" border="0" height="187" width="252" /></a></p>
<p>We’re going to get rid of it. And the ScrollViewer for good measure.</p>
<p>Step 3) Where the ScrollViewer is, put in a ListView or a DataGrid, whichever one you’re using.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0015.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0015-thumb.png" title="clip_image001[5]" style="border: 0px none ; display: inline" alt="clip_image001[5]" border="0" height="132" width="255" /></a></p>
<p>Now, go the properties of that ListView or DataGrid and click on the box to the right of “ItemsSource”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image00111.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image00111-thumb.png" title="clip_image001[11]" style="border: 0px none ; display: inline" alt="clip_image001[11]" border="0" height="60" width="168" /></a></p>
<p>and, in the resulting menu, select “Template Binding –&gt; ItemsSource”.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0017.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image0017-thumb.png" title="clip_image001[7]" style="border: 0px none ; display: inline" alt="clip_image001[7]" border="0" height="294" width="438" /></a></p>
<p>Set the DataContext of the ListView or DataGrid to the DataContext of the parent ComboBox using the same process.</p>
<p>And… you’re done! Open the ComboBox and you will see that you can select items in the ListView or DataGrid in the ComboBox dropdown and see those items change the selection of the ComboBox.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image00113.png"><img src="http://www.designersilverlight.com/wp-content/uploads/2008/10/clip-image00113-thumb.png" title="clip_image001[13]" style="border: 0px none ; display: inline" alt="clip_image001[13]" border="0" height="193" width="545" /></a></p>
<p>You’ll notice that this is probably not yet an ideal solution. For example, when we select an item, the dropdown doesn’t automatically close. Your best bet is to use the SelectionChanged event to trigger some logic to close the ComboBox dropdown.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/10/01/how-to-use-a-listview-or-datagrid-in-a-combobox-drop-down-without-a-line-of-code/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+To+Use+a+ListView+or+DataGrid+In+a+ComboBox+Drop+Down+%28Without+A+Line+Of+Code%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D365" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+To+Use+a+ListView+or+DataGrid+In+a+ComboBox+Drop+Down+%28Without+A+Line+Of+Code%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D365" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/10/01/how-to-use-a-listview-or-datagrid-in-a-combobox-drop-down-without-a-line-of-code/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Styling the ComboBox Dropdown (popup)</title>
		<link>http://www.designersilverlight.com/2008/03/24/styling-the-combobox-dropdown-popup/</link>
		<comments>http://www.designersilverlight.com/2008/03/24/styling-the-combobox-dropdown-popup/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 03:36:25 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[cornerradius]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[padding]]></category>
		<category><![CDATA[Popup]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2008/03/24/styling-the-combobox-dropdown-popup/</guid>
		<description><![CDATA[ This tutorial derives from the general &#8220;How to Style the ComboBox&#8221; set of tutorials. First let&#8217;s make sure you&#8217;re in the right place. In this tutorial, we&#8217;re going to style the comboBox drop down (also known as the ComboBox popup) seen highlighted in red below. We will not be styling the items inside the dropdown [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_example.png" title="CB_Image_1"></a> This tutorial derives from the general &#8220;<a href="http://www.designersilverlight.com/2008/02/07/the-wpf-designers-guide-to-styling-the-combobox/">How to Style the ComboBox</a>&#8221; set of tutorials.</p>
<p>First let&#8217;s make sure you&#8217;re in the right place. In this tutorial, we&#8217;re going to style the comboBox drop down (also known as the ComboBox popup) seen highlighted in red below.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_example.png" alt="CB_Image_1" /></p>
<p>We will not be styling the items inside the dropdown (highlighted in blue). You can learn how to do that here.</p>
<p>So… let&#8217;s just go after some of the basics in styling the dropdown. We&#8217;ll give it a new background, a new border and we&#8217;ll round the edges to make it just a little more bubbly.</p>
<p>To start out, we&#8217;ll need to get to our comboBox control template, so right click on the comboBox in the Objects and Timeline window and go to &#8220;<strong>Edit Control Parts (Template) -&gt; Edit a Copy…</strong>&#8221;</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_edittemplate.png" alt="CB_Image_2" /></p>
<p>Name it something you like and we&#8217;re on our way. </p>
<p>We&#8217;ll be editing the <strong>PART_Popup</strong>. Whatever you do, don&#8217;t change the name to this sucker. Whenever you see a &#8220;PART_Something&#8221;, it is a necessary part of that specific control (hence the naming convention).</p>
<p>The ComboBox dropdown (which we&#8217;ll be calling a popup for the remainder of this post)<span>  </span>is made up of a low cost drop shadow (see <a href="http://www.designersilverlight.com/2008/02/08/wpf-drop-shadows-on-the-cheap/">more on that here</a>), a border, a scrollviewer and the itemsPresenter.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_guts.png" alt="CB_Image_3" /></p>
<p>Most of the standard styling we might want to do is probably going to happen in the Border titled DropDownBorder. We can alter the background and the border brushes easily enough by just changing them in the Properties window. But you may notice some quirky behavior from our scrollviewer when we change the CornerRadius. Below, I&#8217;ve changed the CornerRadius to &#8220;<strong>0,0,10,10</strong>&#8221; and we can see that we lose part of the corner under the scrollviewer.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_borderconer.png" alt="CB_Image_4" /></p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_corner_eh.png" alt="CB_Image_5" /></p>
<p>We can solve this easily enough by adding some padding through the Border. Below I&#8217;ve added a padding of &#8220;<strong>0,0,2,6</strong>&#8220;.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/03/cb_dropdown_corner_fixed.png" alt="CB_Image_6" /></p>
<p>Better, but not really ideal. In a perfect world, we would be able to say that the border us able to cut off its content in that nice pretty rounded manner.<span>  </span>(If anyone knows how to do that… let me know, I haven&#8217;t given it hours of thought yet, but I&#8217;d love to know). In this case, however, this sub-optimization is the price we&#8217;re going to have to pay if we don&#8217;t want to have to go in and mess with the scrollbar style and template.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/03/24/styling-the-combobox-dropdown-popup/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Styling+the+ComboBox+Dropdown+%28popup%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D193" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Styling+the+ComboBox+Dropdown+%28popup%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D193" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/03/24/styling-the-combobox-dropdown-popup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How Do I Style The ComboBox Items?</title>
		<link>http://www.designersilverlight.com/2008/02/07/how-do-i-style-the-combobox-items/</link>
		<comments>http://www.designersilverlight.com/2008/02/07/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.designersilverlight.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 [...]]]></description>
			<content:encoded><![CDATA[<p>This is actually a continuation of my post on <a href="http://www.designersilverlight.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.designersilverlight.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-139"></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.designersilverlight.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.designersilverlight.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.designersilverlight.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.designersilverlight.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.designersilverlight.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.designersilverlight.com/wp-content/uploads/2008/02/finalcomboboxitems.png" alt="FinalComboBoxItems" /></p>
<p>Much better.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/02/07/how-do-i-style-the-combobox-items/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+Do+I+Style+The+ComboBox+Items%3F+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D139" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+Do+I+Style+The+ComboBox+Items%3F+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D139" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/02/07/how-do-i-style-the-combobox-items/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The WPF Designers Guide to Styling The ComboBox</title>
		<link>http://www.designersilverlight.com/2008/02/07/the-wpf-designers-guide-to-styling-the-combobox/</link>
		<comments>http://www.designersilverlight.com/2008/02/07/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.designersilverlight.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 [...]]]></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.designersilverlight.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.designersilverlight.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-146"></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.designersilverlight.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.designersilverlight.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.designersilverlight.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.designersilverlight.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.designersilverlight.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.designersilverlight.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>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/02/07/the-wpf-designers-guide-to-styling-the-combobox/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=The+WPF+Designers+Guide+to+Styling+The+ComboBox+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D146" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=The+WPF+Designers+Guide+to+Styling+The+ComboBox+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D146" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/02/07/the-wpf-designers-guide-to-styling-the-combobox/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How Do I Wrap Text (or Add TextEllipsis) In The ComboBox?</title>
		<link>http://www.designersilverlight.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/</link>
		<comments>http://www.designersilverlight.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 07:28:34 +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[]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[DataTemplate]]></category>
		<category><![CDATA[itemtemplate]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[texttrimming]]></category>
		<category><![CDATA[textwrapping]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/</guid>
		<description><![CDATA[I&#8217;ve been spending the past several days fighting with the ComboBox in an attempt to make it so something very simple: Wrap text inside the combo box. I&#8217;ve finally figured it out, so I thought I&#8217;d share. OK, first of all, make sure that your ComboBox is hooked up to something, even if that something [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending the past several days fighting with the ComboBox in an attempt to make it so something very simple: Wrap text inside the combo box. I&#8217;ve finally figured it out, so I thought I&#8217;d share.</p>
<p>OK, first of all, make sure that your ComboBox is hooked up to something, even if that something is some random RSS feed. I have<a href="http://www.designersilverlight.com/2007/12/13/how-do-i-connect-an-rss-feed-to-my-listviewlistboxwhatever/"> a post that can help you with that over here</a>. Bind your comboBox to the &#8220;Items&#8221; part of the New York Times RSS feed.</p>
<p>You need to do this because, if you do not, you will have to set the same data template to every single ComboBoxItem that you add to the ComboBox. And that&#8217;s just no fun.</p>
<p>Starting out, your ComboBox should look something like this:</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/originalcombobox.png" alt="ComboBoxDefault" /></p>
<p>Right click on your ComboBox and select &#8220;<strong>Edit Other Templates -&gt; Edit Generated Items (ItemTemplate)-&gt; Create Empty…</strong>&#8221; Give your new data template a name and Blend will take you into the Data Template design.</p>
<p><span id="more-124"></span></p>
<p>Put a Grid in your data template and a TextBlock inside that. Set the TextWrapping in your TextBlock to <strong>&#8220;Wrap&#8221;</strong> and set your binding. You can set the binding visually by clicking on the little box to the right of the <strong>&#8220;Text&#8221;</strong> property in the TextBlock and going to the <strong>&#8220;DataBinding&#8221;</strong> option.</p>
<p>In the resulting binding screen, go to the Explicit Data Context tab and click on whatever you want. I chose &#8220;description&#8221; because it is generally long enough to wrap in almost all cases.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/descriptiondatacontext.png" alt="ComboBoxDescriptionBinding" /></p>
<p>My DataTemplate is shown below for reference.</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">DataTemplate</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">WrappingComboTemplate</font>&#8220;<font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;</font><font color="#800000">Grid</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">Auto</font>&#8221; <font color="#ff0000">Heigh</font>t=&#8221;<font color="#0000ff">Auto</font>&#8220;&gt;<br />
<font color="#0000ff">&lt;</font><font color="#800000">TextBlock</font> <font color="#ff0000">Text</font>=&#8221;<font color="#cc9436">{Binding Mode=OneWay, XPath=description}</font>&#8221; <font color="#ff0000">TextWrapping</font>=&#8221;<font color="#0000ff">Wrap</font>&#8220;<font color="#0000ff">/&gt;<br />
</font>      <font color="#0000ff">&lt;/</font><font color="#800000">Grid</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">DataTemplate</font><font color="#0000ff">&gt;</font></p>
<p>If you&#8217;re trying to give your text ellipses, ignore the TextWrapping property and make your TextBlock property to one of the following:</p>
<p><font color="#ff0000">TextTrimming</font>=&#8221;<font color="#0000ff">WordEllipsis</font>&#8221;</p>
<p><font color="#ff0000">TextTrimming</font>=&#8221;<font color="#0000ff">CharacterEllipsis</font>&#8221;</p>
<p>Your combo box should now look something like this:</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/comboboxhalfdone.png" alt="ComboBoxTextWrapHalfDone" /></p>
<p>This is good. This is progress. But when you open it, it looks like this:</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/comboboxhalfdoneexpanded.png" alt="ComboBoxHalfDoneExpanded" />As you can see, it just keeps going and going. Let&#8217;s fix that.</p>
<p>Right click on your comboBox and go to &#8220;<strong>Edit Control Parts (Template) -&gt; Edit a Copy…&#8221;</strong></p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/controlparttemplatecomboboxtextwrapping.png" alt="ComboBoxControlTemplateCopy" /></p>
<p>Go down to the ScrollViewer that holds the ItemsPresenter.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/comboboxtemplatescrollviewer.png" alt="ComboBoxTemplateScrollViewer" /></p>
<p>Take note… this is an important WPF lesson. Some layouts stretch to contain the items inside them. Unless you put limits on the stretching, they&#8217;ll just go on and on forever. This is really, really bad if you&#8217;re trying to make your text wrap or give your text ellipses because the text element is looking for something that will give it a hard border and an expansive layout won&#8217;t.</p>
<p>This is what has happened here. Because the ScrollViewer HorizontalScrollBarVisibility default is &#8220;Auto&#8221;, the ScrollViewer thinks it has all the space in the world and decides to take advantage of your real-estate generosity.  Lay the smack-down on that insolent ScrollViewer: set the &#8220;HorizontalScrollBarVisibility&#8221; to &#8220;Disabled&#8221;.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/scrollvisibility.png" alt="ScrollViewerVisibility" /></p>
<p>Now, that alone has done exactly nothing. Why? Because the popup that it is placed in still thinks it has all the space in the world. So go to the popup (named PART_Popup) and click on the box next to the &#8220;Width&#8221; property and go to &#8220;DataBinding&#8221;. When the data binding window opens, select the &#8220;Element Property&#8221; tab, then select the fourth item down in the left hand pane and &#8220;ActualWidth&#8221; in the right hand pane.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/databindingpopupwidth.png" alt="DataBindingPopupWidth" /></p>
<p>This will make your comboBox look like this:</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/comboboxalmostdoneexpanded.png" alt="ComboBoxWrapAlmostDonw" /></p>
<p>You can see that the ScrollViewer is slightly cut off… which is irksome. We&#8217;ll solve this by giving our ScrollViewer a &#8220;Margin&#8221; of  &#8220;0,0,4,0&#8243;.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/lastmargintweak.png" alt="LastMarginTweak" /></p>
<p>If this is all you want to do… you&#8217;re done. Me? I can&#8217;t stand the fact that all this text runs together so much.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2008/02/unfinishedpopupstyle.png" alt="UnfinishedPopupStyle" /></p>
<p>The easiest way to deal with is to do some styling back in the DataTemplate we created. The best way to deal with this is to go into the ItemContainerStyle for the ComboBox, which I deal with in my post, <a href="http://www.designersilverlight.com/2008/02/07/how-do-i-style-the-combobox-items/">&#8220;Styling ComboBox Items&#8221;.</a></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+Do+I+Wrap+Text+%28or+Add+TextEllipsis%29+In+The+ComboBox%3F+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D124" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+Do+I+Wrap+Text+%28or+Add+TextEllipsis%29+In+The+ComboBox%3F+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D124" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

