WPF Combobox Styling -


below combobox style code. idea put border around combobox , reuse style.

<application x:class="wpfapplication1.app"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              startupuri="window1.xaml">   <application.resources>     <style x:key="userinputcomboboxstyle"            targettype="{x:type combobox}">       <setter property="template">         <setter.value>           <controltemplate targettype="{x:type combobox}">             <grid>               <border borderbrush="black"                       borderthickness="2"                       verticalalignment="stretch"                       horizontalalignment="stretch" />               <combobox horizontalalignment="stretch"                         verticalalignment="center"                         horizontalcontentalignment="left"                         verticalcontentalignment="center"                         margin="5">               </combobox>             </grid>           </controltemplate>         </setter.value>       </setter>     </style>   </application.resources> </application> 

however after applying style, in resultant combobox combobox items not getting displayed.

<window x:class="wpfapplication1.window1"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="comboboxtest"         height="300"         width="300">   <stackpanel>     <combobox margin="5"               style="{staticresource userinputcomboboxstyle}">       <comboboxitem content="test0"                     isselected="true" />       <comboboxitem content="test1" />       <comboboxitem content="test2" />     </combobox>   </stackpanel> </window> 

can please me working?

kind regards, abbas

============================================================================

finally settled this, still know how can done least number of xaml code.

<grid>   <border borderbrush="black"           borderthickness="2"           cornerradius="5">     <combobox selectedindex="0"               verticalalignment="top"               horizontalalignment="stretch"               verticalcontentalignment="center"               horizontalcontentalignment="center"               borderbrush="black"               borderthickness="5"               margin="5">       <comboboxitem isselected="true">test0</comboboxitem>       <comboboxitem>test1</comboboxitem>       <comboboxitem>test2</comboboxitem>       <comboboxitem>test3</comboboxitem>     </combobox>   </border> </grid> 

combobox has few named parts responsible styling different parts means parts of template must named in order used in correct places. think want style contentpresenterborder. has been explained on msdn site.

msdn example:

<setter property="template">    <setter.value>       <controltemplate targettype="combobox">          <grid>             <border x:name="contentpresenterborder">                <grid>                   <togglebutton x:name="dropdowntoggle"/>                   <contentpresenter x:name="contentpresenter" />                      <textblock text=" " />                   </contentpresenter>                </grid>             </border>          </grid>       </controltemplate>    </setter.value> </setter> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -