xaml - WPF Usercontrol with content presenter for a group of buttons -




i'm trying figure out how create user control act modal group of togglebuttons. don't want go radio button route because user has able deselect everything. need list support vertical , horizontal presentation.

i'd have control looks in xaml.

<mycontrol>     <grid>         <grid.columndefinitions>...</grid.columndefinitions>         <togglebutton />         <togglebutton />         <togglebutton />         ...         <togglebutton />     </grid> </mycontrol> 

i think grid may not correct layout option here since don't know how many buttons i'll have.

you handle routed checked event according following sample code.

xaml:

<grid togglebutton.checked="grid_checked">     <grid.columndefinitions>         <columndefinition />         <columndefinition />         <columndefinition />     </grid.columndefinitions>     <togglebutton content="a" />     <togglebutton content="b" grid.column="1" />     <togglebutton content="c" grid.column="2" /> </grid> 

code:

private void grid_checked(object sender, routedeventargs e) {     grid grid = sender grid;     togglebutton toggledbutton = e.originalsource togglebutton;     ienumerable<togglebutton> alltogglebuttons = grid.children.oftype<togglebutton>();     foreach (togglebutton togglebutton in alltogglebuttons)         if (togglebutton != toggledbutton)             togglebutton.ischecked = false; } 

only 1 togglebutton in grid can checked simultaneously, togglebuttons may unchecked.





wiki

Comments

Popular posts from this blog

elasticsearch - what is the equivalent data type for geo_point in hibernate search? -

Jenkins: find build number for git commit -

firebase - How to wait value in Ionic 2 -