c# - Selected radio button is changed when selected tab is changed -


i have tab control bound observable collection. each tab displays single radio button group. when tab changed, reason deselects selected radio button.

each item in observable collection stores selected radio button own tab. believe means can't interfere each other. recognize 1 radio button can selected per group. yet, each tab in own group. why selected radio button being changed when tab changes?

xaml

<tabcontrol x:name="maintabcontrol" >     <tabcontrol.itemtemplate>         <datatemplate>             <textblock text="{binding tabname}"></textblock>         </datatemplate>     </tabcontrol.itemtemplate>     <tabcontrol.contenttemplate>         <datatemplate>             <grid>                 <grid.columndefinitions>                     <columndefinition width="1*" />                     <columndefinition width="1*" />                     <columndefinition width="1*" />                 </grid.columndefinitions>                 <radiobutton x:name="radiobuttonx"                              grid.column="0"                              verticalalignment="center"                              content="x"                              ischecked="{binding xchecked}" />                 <radiobutton x:name="radiobuttony"                              grid.column="1"                              verticalalignment="center"                              content="y"                              ischecked="{binding ychecked}" />                 <radiobutton x:name="radiobuttonz"                              grid.column="2"                              verticalalignment="center"                              content="z"                              ischecked="{binding zchecked}" />             </grid>         </datatemplate>     </tabcontrol.contenttemplate> </tabcontrol> 

c#

public partial class mainwindow {     public observablecollection<radiobuttonsettings> listofbuttonsettings { get; set; }      public mainwindow()     {         listofbuttonsettings = new observablecollection<radiobuttonsettings>         {             new radiobuttonsettings {tabname = "tab1"},             new radiobuttonsettings {tabname = "tab2"},             new radiobuttonsettings {tabname = "tab3"}         };          initializecomponent();        maintabcontrol.itemssource = listofbuttonsettings;     } }  public class radiobuttonsettings {     public string tabname { get; set; }     public bool xchecked { get; set; }     public bool ychecked { get; set; }     public bool zchecked { get; set; }      public radiobuttonsettings()     {         xchecked = true;     } } 

this issue described here

the workaround use radiobuttonextended class written in above link. can change xaml following , work expected:

 <radiobuttonextended x:name="radiobuttonx"      grid.column="0"      verticalalignment="center"      content="x"      ischeckedreal="{binding xchecked}" />  <radiobuttonextended x:name="radiobuttony"      grid.column="1"      verticalalignment="center"      content="y"      ischeckedreal="{binding ychecked}" />  <radiobuttonextended x:name="radiobuttonz"      grid.column="2"      verticalalignment="center"      content="z"      ischeckedreal="{binding zchecked}" /> 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -