WPF - The buttons next to each other -


i have button , under him text , these buttons next each other served under him. code: userview.xaml:

<wrappanel orientation="horizontal" horizontalalignment = "left">         <itemscontrol itemssource = "{binding path = users}">             <itemscontrol.itemtemplate>                 <datatemplate>                     <stackpanel orientation = "vertical">                         <button style="{staticresource userbutton}" content="{binding name}"></button>                         <rectangle style="{staticresource userbuttonstatus}"                                         fill="{binding color}" tooltip="{binding tooltip}"/>                     </stackpanel>                 </datatemplate>             </itemscontrol.itemtemplate>         </itemscontrol>     </wrappanel> 

mainwindow.xaml:

 <stackpanel grid.row="0" grid.column="0" orientation="vertical">             <textblock style="{staticresource title}">users</textblock>             <view:userview x:name="userview">                 <view:userview.datacontext>                     <binding path="userviewmodel" source="{staticresource servicelocator}"/>                 </view:userview.datacontext>             </view:userview>         </stackpanel> 

required:

enter image description here

actual (wrong):

enter image description here

you need overwrite items controls panel

items control display each item underneath each other default.

here code add make sure inside items control tab have done item template:

<itemscontrol.itemspanel>      <itemspaneltemplate>            <wrappanel/>      </itemspaneltemplate> </itemscontrol.itemspanel> 

so userview.xaml this:

<itemscontrol itemssource = "{binding path = users}">       <itemscontrol.itemspanel>           <itemspaneltemplate>               <wrappanel/>           </itemspaneltemplate>      </itemscontrol.itemspanel>       <itemscontrol.itemtemplate>           <datatemplate>                <stackpanel orientation = "vertical">                     <button style="{staticresource userbutton}" content="{binding name}"></button>                     <rectangle style="{staticresource userbuttonstatus}" fill="{binding color}" tooltip="{binding tooltip}"/>                </stackpanel>           </datatemplate>      </itemscontrol.itemtemplate> </itemscontrol> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -