Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to create and add few Radio Buttons dynamically in WPF while using MVVM design pattern ?

$
0
0

  I am having a StackPanel under which I have to create and add few RadioButtons  based on some  dynamic data. I don't want to create  RadioButton objects  in my  .cs  file  which  violates  the  MVVM  pattern.  So I tried the Observable Collection class  for RDOItemCollection.  My xaml  looks  like :-

 <StackPanel>

 <ItemControl ItemSource ={Binding RDOItemCollection}>

<ItemsControl.ItemTemplate>

<RadioButton Content ={Binding Path = RadioBtnName}">

<ItemsControl.ItemTemplate>

</ItemsCotrol>

</StackPanel>

When I run this  WPF  application,  I don't see  the  RadioButton contents/text. Is  something wrong in my Binding metod.  What is  the simple  way to  create and  add  radiobutton with proper content and checked property which is  coming  from  collection class ?

Please  suggest me to implement in MVVM for the  dynamic control creation of RadioButtons. Thanks.






Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>