WPF using StackPanel within a a menu -
i have wpf application using side menu. in 1 section of menu have header menuitem , 2 sub menuitems. change background on 2 sub menuitems show difference. there slight gap between 2 sub menuitems different color. want background of both sub menuites same not gap in between. here menu code:
<menuitem x:name="mireplacelf" header="replace line feeds" height="24" verticalalignment="center" tooltip="replace line feeds in choosen fields replacement character." /> <menuitem x:name="smidbfile" header="database table" click="menuitem_click_rlfdbdatabase" background="#ffbeebf7" margin="15,0,0,0" tooltip="replace line feeds on fields in database table." /> <menuitem x:name="smiexceltextfile" header="excel or text file" height="24" verticalalignment="top" click="menuitem_click_rlfexceltext" background="#ffbeebf7" margin="15,0,0,0" tooltip="choose excel/text file." />
i tried putting 2 sub menuitems within stackpanel. gives me ability have uniform background want sub menuitems shifted right way much. want small indent on 2 sub menuitem. can't find way menuitems alligned left. here code stackpanel.
<menuitem x:name="mireplacelf" header="replace line feeds" height="24" verticalalignment="center" tooltip="replace line feeds in choosen fields replacement character." /> <stackpanel background="#ffbeebf7"> <menuitem x:name="smidbfile" header="database table" click="menuitem_click_rlfdbdatabase" background="#ffbeebf7" margin="0,0,0,0" tooltip="replace line feeds on fields in database table." /> <menuitem x:name="smiexceltextfile" header="excel or text file" height="24" click="menuitem_click_rlfexceltext" background="#ffbeebf7" margin="0,0,0,0" tooltip="choose excel/text file." /> </stackpanel>
here full xaml code, has been changed use suggestions ed plunkett
<window x:class="textutilities.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:textutilities" mc:ignorable="d" title="text utilites" x:name="textutils" height="420" width="900" left="100" top="30" resizemode="canminimize" windowstartuplocation="centerscreen" background="#ffdbf4fb"> <window.resources> <style targettype="menuitem" basedon="{staticresource {x:type menuitem}}" x:key="rlfitem"> <setter property="margin" value="15,0,0,0" /> <setter property="background" value="#ffbeebf7" /> </style> </window.resources> <grid> <menu horizontalalignment="left" width="150" margin="0,2,0,0" fontfamily="arial" fontsize="14.667" borderthickness="0,2,2,0" borderbrush="#ffe0e0e0" background="#ffdbf4fb"> <menu.itemspanel> <itemspaneltemplate> <stackpanel x:name="spitemspanel" background="#ffdbf4fb" /> </itemspaneltemplate> </menu.itemspanel> <menuitem x:name="mireplacelf" header="replace line feeds" height="24" verticalalignment="center" tooltip="replace line feeds in choosen fields replacement character."/> <menuitem x:name="smidbfile" header="database table" height="24" style="{staticresource rlfitem}" click="menuitem_click_rlfdbdatabase" tooltip="replace line feeds on fields in database table." /> <menuitem x:name="smiexceltextfile" header="excel or text file" height="24" style="{staticresource rlfitem}" click="menuitem_click_rlfexceltext" tooltip="choose excel/text file." /> <menuitem x:name="micreatelf" header="create line feeds" height="24" verticalalignment="center" tooltip="replace replacement characters line feeds." /> <menuitem x:name="miviewtextfield" header="view text field" height="24" verticalalignment="center" click="menuitem_click_viewtextfield" tooltip="display contents of text field. allows see how data displayed in ui." /> <menuitem x:name="miviewsptext" header="view sptext" height="24" verticalalignment="center" click="menuitem_click_viewsptext" tooltip="display field sptd_text table sptextdt. allows see how data displayed in ui." /> <menuitem x:name="misplitlargefile" header="split large file" height="24" verticalalignment="center" click="menuitem_click_slf" tooltip="split large files, on 60mb smaller files." /> <menuitem x:name="mihowto" header="how to" height="24" verticalalignment="center" click="menuitem_click_howto" tooltip="instructions on how use sptext utilities." /> <separator style="{staticresource {x:static toolbar.separatorstylekey}}" /> <menuitem header="close" height="24" verticalalignment="center" click="menuitem_click_close" /> </menu> <grid x:name="grdrlfdatabase" visibility="visible" height="350" margin="155,0,0,0" verticalalignment="top"> <textbox x:name="txtrlfdbtitle" isreadonly="true" textwrapping="wrap" text="process clean database table , create pipe delimited text file. may type in server instance or select 1 list. once server choosen please cliack 'load db info' button." horizontalalignment="left" height="62" margin="10,4,0,0" verticalalignment="top" width="659" fontfamily="arial" fontsize="16" padding="5,1,1,1" background="#ffdbf4fb" borderbrush="gray" borderthickness="1"/> <label x:name="lblrlfdbinstance" content="enter database instance:" horizontalalignment="left" height="28" margin="5,87,0,0" verticalalignment="top" width="175" fontfamily="arial" fontsize="14.667"/> <combobox x:name="cbxrlfdbinstances" x:fieldmodifier="public" horizontalalignment="left" height="28" margin="189,87,0,0" verticalalignment="top" width="250" fontfamily="arial" fontsize="14.667" iseditable="true"/> <button x:name="btnrlfdbloaddbinfo" content="load db info" horizontalalignment="left" height="26" margin="475,89,0,0" verticalalignment="top" width="101" fontfamily="arial" fontsize="14.667" click="btnrlfdbloaddbinfo_click" background="#ffeeffff" tooltip="click here after choosing or typing in datbase instance. populate database list."/> <label x:name="lblrlfdbname" content="choose database:" horizontalalignment="left" height="28" margin="5,131,0,0" verticalalignment="top" width="175" fontfamily="arial" fontsize="14.667"/> <combobox x:name="cbxrlfdbname" x:fieldmodifier="public" horizontalalignment="left" height="28" margin="189,132,0,0" verticalalignment="top" width="250" fontfamily="arial" fontsize="14.667" iseditable="true" selectionchanged="cbxrlfdbname_selectionchanged" tooltip="once database choosen table list automatically populated."/> <label x:name="lblrlfdbtablename" content="choose table:" horizontalalignment="left" height="28" margin="5,176,0,0" verticalalignment="top" width="175" fontfamily="arial" fontsize="14.667"/> <combobox x:name="cbxrlfdbtablename" x:fieldmodifier="public" horizontalalignment="left" height="28" margin="189,177,0,0" verticalalignment="top" width="250" fontfamily="arial" fontsize="14.667" iseditable="true" /> <label x:name="lblrlfdboutputname" content="choose output folder:" horizontalalignment="left" height="28" margin="5,233,0,0" verticalalignment="top" width="175" fontfamily="arial" fontsize="14.667"/> <textbox x:name="txtrlfdboutputfolder" x:fieldmodifier="public" isreadonly="true" horizontalalignment="left" height="50" margin="189,222,0,0" textwrapping="wrap" text="" verticalalignment="top" width="250" fontfamily="arial" fontsize="14.667" /> <button x:name="btnrlfdbbrowsefolder" content="browse..." x:fieldmodifier="public" horizontalalignment="left" height="26" margin="475,235,0,0" verticalalignment="top" width="74" fontfamily="arial" fontsize="14.667" background="#ffeeffff" click="btnrlfdbbrowsefolder_click" tooltip="choose folder text file saved to. file named same table '_duc' appended end."/> <button x:name="btnrlfdbsubmit" content="submit" x:fieldmodifier="public" horizontalalignment="left" height="26" margin="261,300,0,0" verticalalignment="top" width="74" fontfamily="arial" fontsize="14.667" background="#ffeeffff" click="btnrlfdbsubmit_click"/> </grid> <grid x:name="grdrlfexceltext" visibility="hidden" height="320" width="750" margin="150, 0, 0 0" verticalalignment="top"> <label x:name="lblrlffileinfo" content="process replace line feeds in text fields." horizontalalignment="left" margin="3,15,0,0" verticalalignment="top" width="583" height="30" fontfamily="arial" fontsize="18.667" fontweight="bold"/> <label x:name="lblrlffilename" content="enter filename:" horizontalalignment="left" margin="3,79,0,0" verticalalignment="top" width="162" height="30" fontfamily="arial" fontsize="16"/> <textbox x:name="txtrlffilename" horizontalalignment="left" height="50" margin="186,70,0,0" textwrapping="wrap" verticalalignment="top" width="400" verticalcontentalignment="center" fontfamily="arial" fontsize="16" fontweight="bold" background="#ffdbf4fb" textchanged="txtrlffilename_textchanged" /> <button x:name="btnrlffilebrowse" content="browse..." horizontalalignment="left" margin="630,84,0,0" verticalalignment="top" width="89" fontfamily="arial" fontsize="16" background="#ffdbf4fb" click="btnrlffilebrowse_click"/> <label x:name="lblrlfoutputfolder" content="choose output folder:" horizontalalignment="left" margin="3,149,0,0" verticalalignment="top" width="180" height="30" fontfamily="arial" fontsize="16"/> <textbox x:name="txtrlfoutputfolder" horizontalalignment="left" height="50" margin="186,138,0,0" textwrapping="wrap" verticalalignment="top" width="400" verticalcontentalignment="center" fontfamily="arial" fontsize="16" fontweight="bold" background="#ffdbf4fb" textchanged="txtrlfoutputfolder_textchanged"/> <button x:name="btnrlffolderbrowse" content="browse..." horizontalalignment="left" margin="630,154,0,0" verticalalignment="top" width="89" fontfamily="arial" fontsize="16" background="#ffdbf4fb" click="btnrlffolderbrowse_click"/> <label x:name="lblrlffielddelim" content="field delimiter:" horizontalalignment="left" margin="190,202,0,0" verticalalignment="top" width="118" height="30" fontfamily="arial" fontsize="16"/> <textbox x:name="txtrlffielddelim" horizontalalignment="left" height="22" margin="312,206,0,0" textwrapping="wrap" verticalalignment="top" width="18" verticalcontentalignment="center" fontfamily="arial" fontsize="16" fontweight="bold" background="#ffdbf4fb" textchanged="txtrlffilename_textchanged" maxlength="2" horizontalcontentalignment="center" /> <checkbox x:name="chbxrlfheaders" content="has header row" horizontalalignment="left" height="17" margin="430,208,0,0" verticalalignment="top" width="149" fontfamily="arial" fontsize="16" checked="chbxrlfheaders_checked" unchecked="chbxrlfheaders_unchecked"/> <button x:name="btnrlfsubmit" content="submit" horizontalalignment="left" margin="319,259,0,0" verticalalignment="top" width="82" height="31" background="#ffdbf4fb" fontfamily="arial" fontsize="16" click="btnrlfsubmit_click"/> </grid> </grid> </window>
you can create menuitem style changes padding or margin (your choice; try both) , background color menu items apply to, , set on whichever items chose:
<window.resources> <style targettype="menuitem" basedon="{staticresource {x:type menuitem}}" x:key="specialitem" > <setter property="margin" value="15,0,0,0" /> <setter property="borderthickness" value="0" /> <setter property="background" value="#ffbeebf7" /> </style> </window.resources>
...
<menuitem header="foo" /> <menuitem header="bar" style="{staticresource specialitem}" /> <menuitem header="baz" style="{staticresource specialitem}" />
the mouse-hover state little funny, unfortunately. default wpf menuitem
template, or @ least 1 i'm seeing here, need replace entire control template change that. can go there if need to; let me know.
update
how add image stack overflow question: edit question, click "add picture" icon highlighted in orange.
Comments
Post a Comment