c# - How can I bind to whether any/none `RadioButton` of a certain group is selected? -


how can bind whether any/none radiobutton of group checked?

i have, say, 4 radiobuttons. none of them checked, "next" button disabled. user must make selection in order enable "next" button , able proceed.

first solution not efficient since every new radiobutton entails add datatrigger:

  <stackpanel>     <radiobutton name="x1"/>     <radiobutton name="x2"/>     <radiobutton name="x3"/>     <radiobutton name="x4"/>     <button content="click">         <button.style>             <style targettype="button">                 <setter property="isenabled" value="false"/>                 <style.triggers>                     <datatrigger binding="{binding elementname=x1, path=ischecked}" value="true">                         <setter property="isenabled" value="true"/>                     </datatrigger>                     <datatrigger binding="{binding elementname=x2, path=ischecked}" value="true">                         <setter property="isenabled" value="true"/>                     </datatrigger>                     <datatrigger binding="{binding elementname=x3, path=ischecked}" value="true">                         <setter property="isenabled" value="true"/>                     </datatrigger>                     <datatrigger binding="{binding elementname=x4, path=ischecked}" value="true">                         <setter property="isenabled" value="true"/>                     </datatrigger>                 </style.triggers>             </style>         </button.style>     </button> </stackpanel> 

latter in turn based on mvvm. create property ischecked in viewmodel , whenever radiobutton checked sets ischecked value true , button based on value sets isenabled property.

xaml:

<stackpanel>     <stackpanel.resources>         <style targettype="radiobutton">             <setter property="command" value="{binding radiobuttoncheckedcommand}"/>         </style>     </stackpanel.resources>     <radiobutton name="x1"/>     <radiobutton name="x2"/>     <radiobutton name="x3"/>     <radiobutton name="x4"/>     <button content="click" isenabled="{binding ischecked}"/> </stackpanel> 

viewmodel:

    class mainviewmodel : inotifypropertychanged {     private bool _ischecked;      public bool ischecked     {         { return _ischecked; }         set         {             _ischecked = value;             onpropertychanged();         }     }      private relaycommand _radiobuttoncheckedcommand;      public relaycommand radiobuttoncheckedcommand     {                 {             return _radiobuttoncheckedcommand ??                    (_radiobuttoncheckedcommand = new relaycommand(() => ischecked = true));         }     }      public void onpropertychanged([callermembername] string propertyname = null)     {         if (propertychanged != null)             propertychanged(this, new propertychangedeventargs(propertyname));     }      public event propertychangedeventhandler propertychanged; } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -