wpf - MenuItem with image as header ignores alignment -


first of all, know there lot of questions alignment in wpf, , i've read of them, none seems work in case...

what have

i've menu, third menuitem doesn't have text image. exact, one:

what have

i want element right aligned, after looking @ examples , problem alignment questions in so, i'm using following code:

<menuitem horizontalalignment="right" horizontalcontentalignment="right">   <menuitem.header>     <stackpanel>       <image source="resources/img/donarboton.gif" uselayoutrounding="false" />     </stackpanel>   </menuitem.header> </menuitem> 

problem

as can see, whith horizontalalignment set right, doesn't appear on right side.

i've read , found menu is, need have same property set stretch, i've tried no success. tried dockpanel menu located (just try, i'm not used wpf yet), nothing either.

i've tried add text element after image element too, in order see if problem menuitem or other thing in configuration, didn't move right side either.

what doing wrong?

there's full dockpanel code:

<dockpanel x:name="superiordock" height="25" lastchildfill="false" verticalalignment="top" width="307">   <menu x:name="superiormenu" width="307"  height="25" dockpanel.dock="top" horizontalalignment="stretch" >     <menuitem header="{binding xpath=@topmenu_1}">       <menuitem header="{binding xpath=@topmenu_2}"/>       <menuitem header="{binding xpath=@topmenu_3}"/>       <separator/>       <menuitem header="{binding xpath=@topmenu_4}"/>       <separator/>       <menuitem header="{binding xpath=@topmenu_5}"/>     </menuitem>     <menuitem header="{binding xpath=@topmenu_6}">       <menuitem header="{binding xpath=@topmenu_7}"/>       <separator/>       <menuitem header="{binding xpath=@topmenu_8}"/>     </menuitem>     <menuitem horizontalalignment="right" horizontalcontentalignment="right">       <menuitem.header>         <stackpanel>           <image source="resources/img/donarboton.gif" uselayoutrounding="false" />         </stackpanel>       </menuitem.header>     </menuitem>   </menu> </dockpanel> 

thanks in advance

use this:

<dockpanel x:name="superiordock" height="25" lastchildfill="false" verticalalignment="top" width="307">   <menu x:name="superiormenu" width="307"  height="25" dockpanel.dock="top" horizontalalignment="stretch">     <menu.itemspanel>       <itemspaneltemplate>         <dockpanel horizontalalignment="stretch" />       </itemspaneltemplate>     </menu.itemspanel>     <menuitem header="{binding xpath=@topmenu_1}">       <menuitem header="{binding xpath=@topmenu_2}"/>       <menuitem header="{binding xpath=@topmenu_3}"/>       <separator/>       <menuitem header="{binding xpath=@topmenu_4}"/>       <separator/>       <menuitem header="{binding xpath=@topmenu_5}"/>     </menuitem>     <menuitem header="{binding xpath=@topmenu_6}">       <menuitem header="{binding xpath=@topmenu_7}"/>       <separator/>       <menuitem header="{binding xpath=@topmenu_8}"/>     </menuitem>     <menuitem horizontalalignment="right">       <menuitem.header>         <stackpanel>           <image source="resources/img/donarboton.gif" uselayoutrounding="false" />         </stackpanel>       </menuitem.header>     </menuitem>   </menu> </dockpanel> 

the default itemspanel of menu uses wrappanel. panel defined in itemspanel used container of menuitems. wrappanel doesn't respect horizontalalignment property of children. that's why change itemspanel 1 support this: dockpanel.


Comments