WPF does not provide a radiobuttonlist control like ASP. NET. Fortunately, we can use the powerful functions of WPF styles and templates to implement this function with pure XAML code.
<Window X: class = "controltest2.listboxtest2" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns: S = "CLR-namespace: system; Assembly = mscorlib"> <window. resources> <X: array type = "{X: type S: string}" X: Key = "data"> <s: String> option1 </s: string> <s: String> option2 </S: String> <s: String> option3 </S: String> </X: array> </window. resources> <Stackpanel datacontext = "{staticresource data}"> <textblock margin = "5"> <textblock text = "current option: "/> <textblock text =" {binding/} "/> </textblock> <ListBox itemssource =" {binding} "issynchronizedwithcurrentitem =" true "width =" 240 "Height = ""60" horizontalalignment = "Left"> <ListBox. itemcontainerstyle> <style targettype = "{X: Type listboxitem}"> <setter property = "template"> <setter. value> <controltem Plate targettype = "{X: Type listboxitem}"> <radiobutton ischecked = "{binding Path = isselected, relativesource = {relativesource templatedparent} "content =" {templatebinding content} "/> </controltemplate> </setter. value> </setter> </style> </ListBox. itemcontainerstyle> </ListBox> <! -- This method is simple --> <stackpanel> <radiobutton groupname = "X"> radio1 </radiobutton> <radiobutton groupname = "X"> Radio2 </radiobutton> <radiobutton groupname = "X"> radio3 </radiobutton> </stackpanel> </WINDOW>
Reference: http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/857fdaa9-5c67-4e0a-a1fd-037f72577c76