Failing to add different items in combobox on dynamic radiobutton click
        Posted  
        
            by 
                Steven Wilson
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Steven Wilson
        
        
        
        Published on 2012-11-03T10:51:07Z
        Indexed on 
            2012/11/03
            11:00 UTC
        
        
        Read the original article
        Hit count: 303
        
I am working on radiobuttons and combobox in my wpf App. Although I am a C++ developer, I recently moved to C#. My app deals with dynamic generation of the above mentioned components. Basically I have created 4 dynamic radiobuttons in my app and on clicking each, i should should add different items to my combobox. Here is the code:
XAML:
<ItemsControl ItemsSource="{Binding Children}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" >
                        <RadioButton Content="{Binding RadioBase}"  Margin="0,10,0,0"  IsChecked="{Binding BaseCheck}" GroupName="SlotGroup"  Height="15" Width="80" HorizontalAlignment="Center" VerticalAlignment="Center"/>                            
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
<ComboBox Visibility="{Binding IsRegisterItemsVisible}" ItemsSource="{Binding RegComboList}" SelectedItem="{Binding SelectedRegComboList, Mode=TwoWay}" SelectedIndex="0" />
FPGARadioWidgetViewModel Class:
public ObservableCollection<FPGAViewModel> Children { get; set; }
    public FPGARadioWidgetViewModel()
    {
        Children = new ObservableCollection<FPGAViewModel>();
        Children.Add(new FPGAViewModel() { RadioBase = "Base 0x0", ID = 0 });
        Children.Add(new FPGAViewModel() { RadioBase = "Base 0x40", ID = 1 });
        Children.Add(new FPGAViewModel() { RadioBase = "Base 0x80", ID = 2 });
        Children.Add(new FPGAViewModel() { RadioBase = "Base 0xc0", ID = 3 });            
    }
FPGAViewModel Class:
private bool sBaseCheck;
    public bool BaseCheck
    {
        get { return this.sBaseCheck; }
        set
        {
            this.sBaseCheck = value;                
            AddComboItems();
            this.OnPropertyChanged("BaseCheck");
        }
    }    
private ObservableCollection<string> _RegComboList;
    public ObservableCollection<string> RegComboList
    {
        get { return _RegComboList; }
        set
        {
            _RegComboList = value;
            OnPropertyChanged("RegComboList");
        }
    }        
private void AddComboItems()
    {
        int baseRegister = 0x40 * ID;
        ObservableCollection<string> combo = new ObservableCollection<string>();            
        for (int i = 0; i < 0x40; i++)
        {
            int reg = (i * 8) + baseRegister;
            combo[i] = "0x" + reg.ToString("X");
        }
        RegComboList = new ObservableCollection<String>(combo);
        OnPropertyChanged("RegComboList");
    }
private bool isRegisterItemsVisible = false;
    public bool IsRegisterItemsVisible
    {
        get { return isRegisterItemsVisible; }
        set
        {
            isRegisterItemsVisible = value;
            OnPropertyChanged("IsRegisterItemsVisible");                
            OnPropertyChanged("RegComboList");
        }
    }
If you notice, on clicking a particular radiobutton, it should add items with different value in combobox based on ID. It has to be made sure that on clicking any radiobutton only the items of that should be added and previous content of combobox should be cleared. I am trying to do the same thing using my above code but nothing seems to appear in combobox when i debug.
Please help :)
© Stack Overflow or respective owner