templates - WPF MenuItem header text is partially hidden -


I show items in a menu, but, for unknown reasons, I'm having trouble showing the whole text menu Here's a screen capture of the problem:

Here is the markup code that I used to template it:

   & Lt; / ItemsPanelTemplate & gt; & Lt; Datatomplate x: key = "sidebiremmetlet" & gt; & Lt; MenuItem command = "{binding}" header = "{binding text}" background = "alisblue" & gt; & Lt; MenuItem.Icon & gt; & Lt; Image width = "16" height = "16" source = "{binding image}" /> & Lt; /MenuItem.Icon> & Lt; / MenuItem & gt; & Lt; / DataTemplate & gt; & Lt; Style x: Key = "SideBarStyle" TargetType = "{x: type menu}" & gt; & Lt; Setter property = "item template" value = "{static resource sidebartystem)" /> & Lt; Setter Property = "Itemspanel" value = "{Static Resources SidebarTypeTemplate}" /> & Lt; Setter property = "background" value = "white" /> & Lt; / Style & gt;  

and to display it:

  & lt; Menu itemsource = "{binding commands}" style = "{static resource sidebarstyling}" />  

I have searched a lot, but nothing does help in solving this problem. I hope there will be some help here.

Thank you.

You are getting strange behavior because you have a menu item within MenuItem by setting ItemTemplate on the menu, You are setting up HeaderTemplate on each MenuItem MenuItem will render your normal template, and where normally the header text will be placed, there will be a whole other menu item. I think the space you see is the reserved place for the input gesture text in the external menu.

Instead, you want to set an ItemContainerStyle that will allow you to set the property on the menu item created by the menu. There is a trick that you need to use so that you can create a separate image object for each menu event. By default, objects included in one style will be shared, and you will get an image object shared by each menuite, but if you put them in a separate resource dictionary, you mark them as not being shared. You can. See more

something like this:

  style x: key = "sidebarstyle" targettype = "{x: type menu}" & gt; & Lt; Setter Property = "Itemspanel" value = "{Static Resources SidebarTypeTemplate}" /> & Lt; Setter property = "background" value = "white" /> & Lt; Setter Property = "ItemContainer Style" & gt; & Lt; Setter.Value & gt; & Lt; Style TargetType = "MenuItem" & gt; & Lt; Style.Resources & gt; & Lt; ResourceDictionary source = "Icon.xaml" /> & Lt; /Style.Resources> & Lt; Setter property = "command" value = "{binding}" /> & Lt; Setter Property = "Header" value = "{Binding Text}" /> & Lt; Setter Property = "Background" Value = "Alice Blue" /> & Lt; Setter property = "symbol" value = "{static resource mark}" /> & Lt; / Style & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt;  

Where Icon.xaml includes:

  & lt; Processing Zone xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" & gt; & Lt; Image x: key = "icon" x: share = "wrong" width = "16" height = "16" source = "{binding image}" /> & Lt; / ResourceDictionary & gt;  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -