Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:31:46+00:00 2026-06-13T08:31:46+00:00

I am working on a WPF application where I need to dynamically generate 2

  • 0

I am working on a WPF application where I need to dynamically generate 2 group boxes which have a radio button, textbox and a combobox inside. Well I have come across a tricky situation where values needs to be different in both groupboxes.

I have two xaml files PCM2PDMView.xaml and PCM2PDMWidgetView.xaml & the viewmodel classes.

PCM2PDMView.xaml:

<UserControl.Resources>
    <DataTemplate x:Key="PCM2PDMDataTemplate">
        <WrapPanel>
            <TextBlock Text="{Binding Description}" Margin="5,5,0,0"/>
            <local:PCM2PDMWidgetView Margin="5,10,5,5"/>
        </WrapPanel>
    </DataTemplate>
</UserControl.Resources>

<Grid Style="{DynamicResource styleBackground}" >
    <ItemsControl ItemTemplate="{StaticResource PCM2PDMDataTemplate}" ItemsSource="{Binding PCM2PDMWidgets}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Grid>

PCM2PDMWidgetView.xaml:

<Grid>
    <GroupBox Height="Auto" HorizontalAlignment="Stretch" Margin="5" Name="groupBox1" VerticalAlignment="Stretch" Width="Auto">
        <Grid>             
            <Grid Grid.Row="1">                   
                <RadioButton Grid.Column="1" Content="Port B" Command="{Binding PortCommand}" IsChecked="{Binding PortCheck}" Height="20" Width="60" HorizontalAlignment="Center" Margin="0,0,0,0" Name="PCM2PDMEnableRadioBtn" VerticalAlignment="Center" />                    
            </Grid>

            <Grid Grid.Row="2">                  

                <ComboBox Grid.Column="1" Height="20" ItemsSource="{Binding PortModeList}" SelectedItem="{Binding SelectedPortModeList, Mode=OneWayToSource}" SelectedIndex="0" HorizontalAlignment="Center" Margin="0,0,0,0" Name="PortModeCombo" VerticalAlignment="Center" Width="110" />
            </Grid>

            <Grid Grid.Row="3">                    
                <ToggleButton Grid.Column="0" Content="Soft Reset" Height="25" Width="105" HorizontalAlignment="Center" Margin="0,0,0,0" Name="SoftResetRadioBtn" VerticalAlignment="Center" />
                <ToggleButton Grid.Column="1" Command="{Binding PCM2PDMEnableCommand}" IsChecked="{Binding PCM2PDMCheck}" Content="PCM2PDM Enable" Height="25" Width="110" HorizontalAlignment="Center" Margin="0,0,0,0" Name="PCM2PDMRadioBtn" VerticalAlignment="Center" />
            </Grid> 

            <Grid Grid.Row="4">                 
                <TextBox Height="25" IsReadOnly="True" Text="{Binding MemAddPoint}" Margin="0" Name="SetRead" />               
            </Grid>
       </Grid>
   </GroupBox>
</Grid>

PCM2PDmViewModel.cs:

public ObservableCollection<PCM2PDMWidgetViewModel> PCM2PDMWidgets { get; set; }

    public PCM2PDMViewModel()
    {
        PCM2PDMWidgets = new ObservableCollection<PCM2PDMWidgetViewModel>();
        PCM2PDMWidgets.Add(new PCM2PDMWidgetViewModel { Description = "PCM2PDM 0", ID = 0 });
        PCM2PDMWidgets.Add(new PCM2PDMWidgetViewModel { Description = "PCM2PDM 1", ID = 1 });            
    }

This generates 2 groupboxes with associated UI controls inside.

PCM2PDMWidgetViewModel.cs:

public ObservableCollection<string> _PortModeList = _PortModeList = new ObservableCollection<string>();
_PortModeList.Add("Normal"); //Adding in Constructor
_PortModeList.Add("Mode 1 - PCM + PDM");
_PortModeList.Add("Mode 2 - PDM only");

public ObservableCollection<string> PortModeList
    {
        get { return _PortModeList; }
        set
        {
            _PortModeList = value;
            OnPropertyChanged("PortModeList");
        }
    }

    private string _selectedPortModeList;
    public string SelectedPortModeList
    {
        get { return _selectedPortModeList; }
        set
        {
            _selectedPortModeList = value;                
            OnPropertyChanged("SelectedPortModeList");
        }
    }

    public string Description {get; set;}      

    public int ID {get; set;}

    public string MemAddPoint {get; set;}

Requirement:

  1. Now if you notice Grid.Row=1 you will find a radiobutton titled Port B, Well my requirement is to have Port B in my 1st groupbox and Port C in my second groupbox. The functionality(buttonclick method) will be common for both but the name must be different. How can we achieve that?

  2. In my combobox I am adding 3 items. Here I want to add Normal and Mode 1 - PCM + PDM in combobox present in 1st groupbox and add Normal, Mode 1 - PCM + PDM and Mode 2 - PDM Only in combobox present in 2nd groupbox. How can that be achieved? 🙂

  3. If you notice Grid.Row=3 you will find PCM2PDMEnable togglebutton. I want to have this togglebutton visible in my 2nd groupbox and not in my first groupbox. How can I do that?

  4. Textbox in Grid.Row=4 has a textbox whose value is (e.g. 0x5). I need to set the text of this textbox as 0x5 in Groupbox 1 and 0x7 in Textbox of Groupbox2. How to do that?

Please Help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:31:47+00:00Added an answer on June 13, 2026 at 8:31 am

    Create a property in your “PCM2PDMWidgetViewModel” say “RadioButtonName” and while creating “PCM2PDMWidgetViewModel” instance set the property to the name you want.. something like this

    PCM2PDMWidgets.Add(new PCM2PDMWidgetViewModel { Description = "PCM2PDM 0", ID = 0, RadioButtonName = "Port B" });
            PCM2PDMWidgets.Add(new PCM2PDMWidgetViewModel { Description = "PCM2PDM 1", ID = 1, RadioButtonName = "Port C" });            
    

    In PCM2PDMWidgetView XAML:

    Change the radio button content to binding “Content=”{Binding RadioButtonName}””

    <Grid Grid.Row="1">                   
                    <RadioButton Grid.Column="1" Content="{Binding RadioButtonName}" Command="{Binding PortCommand}" IsChecked="{Binding PortCheck}" Height="20" Width="60" HorizontalAlignment="Center" Margin="0,0,0,0" Name="PCM2PDMEnableRadioBtn" VerticalAlignment="Center" />   
    
    
            </Grid>
    

    Instead of adding following elements in the constructor.. send them as a List as parameter to the constructor..

    Your Code

    _PortModeList.Add(“Normal”); //Adding in Constructor
    _PortModeList.Add(“Mode 1 – PCM + PDM”);
    _PortModeList.Add(“Mode 2 – PDM only”);

    Solution for 2

    public PCM2PDMWidgetViewModel(List comboBoxItems)
    {
    foreach(item in comboBoxItems)
    {
    _PortModeList.Add(item);
    }
    }

    While creating “PCM2PDMWidgetViewModel” instance send the List as constructor parameter (look at the following code)

    PCM2PDMWidgets.Add(new PCM2PDMWidgetViewModel (new List<string>{"Normal","Mode 1 - PCM + PDM"}) { Description = "PCM2PDM 0", ID = 0, RadioButtonName = "Port B" });
            PCM2PDMWidgets.Add(new PCM2PDMWidgetViewModel(new List<string>{"Normal","Mode 1 - PCM + PDM","Mode 2"}) { Description = "PCM2PDM 1", ID = 1, RadioButtonName = "Port C" });  
    

    For 4

    you can fix this in the same way as radion button name..

    set value for the “MemAddPoint” property in the same way you did for Description and ID. As this property is already binded to the textbox you don’t need to change xaml bindings

    For 3:

    You have to create a new property in “PCM2PDMWidgetViewModel” of type “Visibility” and bind it to the togglebutton visibility property. set the property value while creating instance

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WPF application I'm working on, which performs a SQL query
I am working on a wpf application. Here I need to use System.Windows.Forms.FolderBrowserDialog in
I'm working on a WPF application which should be utilizable with two monitors. In
I'm building a WPF application and working with the MVVM pattern. I have 4
I have a small WPF application that I am working on localizing. I have
I have a WPF application which so far has been client only, but now
I've been working on a WPF application and need to be able to show
I have a working WPF application. I would like to see it running as
I am working on a MVVM wpf application and I need to show various
I have been working on a WPF Application that is essentially a WYSIWYG editor,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.