Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do it by creating your own SelectionBoxItemTemplate attached property and then defining a new style/control template for the ComboBox which uses that template in the content presenter for the selection box area.</p> <p>Here's a suitable attached property:</p> <pre><code>public class ComboBoxExt { public static DataTemplate GetSelectionBoxItemTemplate(DependencyObject obj) { return (DataTemplate) obj.GetValue(SelectionBoxItemTemplateProperty); } public static void SetSelectionBoxItemTemplate(DependencyObject obj, DataTemplate value) { obj.SetValue(SelectionBoxItemTemplateProperty, value); } public static readonly DependencyProperty SelectionBoxItemTemplateProperty = DependencyProperty.RegisterAttached("SelectionBoxItemTemplate", typeof (DataTemplate), typeof (ComboBoxExt), new PropertyMetadata(null)); } </code></pre> <p>To update the ComboBox control template, look for the element named <code>ContentPresenter</code> inside one called <code>ContentPresenterBorder</code> (you can find the default style for ComboBox <a href="http://msdn.microsoft.com/en-us/library/dd334408%28v=vs.95%29.aspx" rel="nofollow">here</a>). You need to remove the name of the ContentPresenter (otherwise the ComboBox will set values for its properties explicitly through code, ignoring the databindings that you set).</p> <p>Here's what the ContentPresenter element in the adjusted control template should look like:</p> <pre><code>&lt;ContentPresenter Margin="{TemplateBinding Padding}" Content="{Binding Path=SelectedItem, RelativeSource={RelativeSource TemplatedParent}}" ContentTemplate="{Binding (a:ComboBoxExt.SelectionBoxItemTemplate), RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"&gt; &lt;/ContentPresenter&gt; </code></pre> <p>Finally, to use this, you would do something like:</p> <pre><code>&lt;ComboBox Style="{StaticResource MyAdjustedComboBoxStyle}" ItemTemplate="{StaticResource MyDropDownAreaTemplate}" Behaviors:ComboBoxExt.SelectionBoxItemTemplate="{StaticResource MySelectionAreaTemplate}"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload