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 8707525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:53:22+00:00 2026-06-13T03:53:22+00:00

I am a C++ developer and recently started working on WPF. I am sorry

  • 0

I am a C++ developer and recently started working on WPF. I am sorry for the weird title since I wasnt sure what to put. In my app, I need to dynamically generate 2 groupboxes which contain buttons, labels, textbox, combobox’s and so on. And once its done, I need to perform some operation on these controls.

I have 2 xaml files PCMGenView.xaml and PCMGenWidgetView.xaml where PCMGenWidgetView.xaml file has the groupbox and is added to the PCMGenView.xaml file. I also have 2 viewmodel classes and a model class. Well let me show you how I have done it:

PCMGenView.xaml

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

<Grid>
    <ItemsControl ItemTemplate="{StaticResource PGenDataTemplate}" ItemsSource="{Binding PGenWidgets}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Grid>

PCMGenWidgetView.xaml:

<Grid>
    <GroupBox Height="Auto" HorizontalAlignment="Stretch" Margin="10" Name="groupBox1" VerticalAlignment="Stretch" Width="Auto">
        <Grid >
              <ComboBox Grid.Column="1" ItemsSource="{Binding PreScalarList}" SelectedItem="{Binding SelectedPreScalarList, Mode=OneWayToSource}" SelectedIndex="0" Height="23" HorizontalAlignment="Center" Margin="0,0,0,0" Name="PCMGenControlCombo" VerticalAlignment="Center" Width="110" /> 
              // Radio Button, Buttons etc are present too                          
        </Grid>
    </GroupBox>
</Grid>

PCMGenWidgetView.xaml.cs:

public partial class PCMGenWidgetView : UserControl
{
    PCMGenWidgetViewModel mPCMGenWidgetViewModel = new PCMGenWidgetViewModel();

    public PCMGenWidgetView()
    {
        InitializeComponent();
        this.DataContext = mPCMGenWidgetViewModel;            
    }
}

PCMGenViewModel:

public ObservableCollection<PCMGenWidgetViewModel> PGenWidgets { get; set; }

    public PCMGenViewModel()
    {
        PGenWidgets = new ObservableCollection<PCMGenWidgetViewModel>();
        PGenWidgets.Add(new PCMGenWidgetViewModel { Description = "PCM Generator 1", ID = 0 });
        PGenWidgets.Add(new PCMGenWidgetViewModel { Description = "PCM Generator 2", ID = 1 });            
    }

PCMGenWidgetViewModel:

private string _description;
    public string Description
    {
        get
        {
            return _description;
        }

        set
        {
            _description = value;
            OnPropertyChanged("Description");
        }
    }

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

    private string _selectedPreScalarList;
    public string SelectedPreScalarList
    {
        get { return _selectedPreScalarList; }
        set
        {
            _selectedPreScalarList = value;
            int Listvalue = PreScalarList.IndexOf(_selectedPreScalarList);
            int ListFinalVal = Listvalue + 1;
            SelectedPreScalar(ListFinalVal);
            OnPropertyChanged("SelectedPreScalarList");
        }
    }

    private int _ID;
    public int ID
    {
        get
        {
            return _ID;
        }

        set
        {
            _ID = value;
            OnPropertyChanged("ID");
        }
    }

    public void SelectedPreScalar(int Select)
    {
        int bitMask;
        bitMask = (0 == ID) ? 0xCF : 0x3F;  // ID always shows 0
        m_controlRegs[0] &= Convert.ToByte(bitMask);
        //m_refClock[0] = Convert.ToByte(18432000 * 2);                                             
    }

Now this gives me 2 groupboxes on startup 🙂 In my combobox I have A,B,C,D as items. Have a look at the combobox binding at how I am able to retrieve the selected value from the combobox. Here I wanna perform the same operation on all these controls but if different values. Well I mean to say something like this which I did in my C++ app:

for( i = 0;  i < 2; i++) //Constructor: Here 2 is used because we have 2 groupboxes
{
    m_pcmGenPrescalar[i] = new ComboBox(String::empty);
    m_pcmGenPrescalar[i]->addItem(String(T("div 1")), 1);
    m_pcmGenPrescalar[i]->addItem(String(T("div 15")), 2);
    m_pcmGenPrescalar[i]->addItem(String(T("div 255")), 3);
    m_pcmGenPrescalar[i]->addItem(String(T("div 65535")), 4);
    m_pcmGenPrescalar[i]->setEditableText(false);
    m_pcmGenPrescalar[i]->setSelectedId(1, true);
    m_pcmGenPrescalar[i]->addListener(this);
    addAndMakeVisible(m_pcmGenPrescalar[i]);
}

for( i = 0;  i < 2; i++) //Here 2 is used because we have 2 groupboxes
{       
    if(m_pcmGenPrescalar[i] == comboBox) //PreScalar Combobox
    {
        unsigned char bitMask = (0 == i) ? 0xCF : 0x3F; Takes the value of i
        m_controlRegs[0] &= bitMask;
        m_refClock[i] = 18432000 * 2;
    }

If you notice above code, you will find the for loop creating the combobox two times and based on which ever combobox is selected value is taken in i. I.e. if first combobox selection is changed then unsigned char bitMask = (0 == i) ? 0xCF : 0x3F; becomes unsigned char bitMask = (0 == 0) ? 0xCF : 0x3F; if second then, unsigned char bitMask = (0 == 1) ? 0xCF : 0x3F;

This is my query. How can I get to know which combobox I have used. Whether I have used PCM Gen 1 combo or PCM Gen 2 combo? This is a tricky situation for me. 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-13T03:53:23+00:00Added an answer on June 13, 2026 at 3:53 am

    Use an ID-property:

        public int ID {get;set;}
        public void SelectedPreScalar(int Select)
        {
            int bitMask;
            bitMask = (0 == ID) ? 0xCF : 0x3F; 
            m_controlRegs[0] &= Convert.ToByte(bitMask);
            m_refClock[0] = Convert.ToByte(18432000 * 2); 
        }
    

    But you also can use a BitMask-Property, which you set at the instanciation:

        public string BitMask {get;set;}
        public void SelectedPreScalar(int Select)
        {
            m_controlRegs[0] &= Convert.ToByte(BitMask);
            m_refClock[0] = Convert.ToByte(18432000 * 2); 
        }
    

    Depending on how you decided, your PCGenViewModel-constructor could look like:

        public PCMGenViewModel()
        {
            PGenWidgets = new ObservableCollection<PCMGenWidgetViewModel>();
            PGenWidgets.Add(new PCMGenWidgetViewModel { Description = "PCM Generator 1", BitMask="0xCF" });
            PGenWidgets.Add(new PCMGenWidgetViewModel { Description = "PCM Generator 2", BitMask="0x3F" });            
        }
    

    or

        public PCMGenViewModel()
        {
            PGenWidgets = new ObservableCollection<PCMGenWidgetViewModel>();
            PGenWidgets.Add(new PCMGenWidgetViewModel { Description = "PCM Generator 1", ID=0 });
            PGenWidgets.Add(new PCMGenWidgetViewModel { Description = "PCM Generator 2", ID=1 });            
        }
    

    I would recommend using the second suggestion, because if you add a third groupbox, you dont have to change your SelectedPreScalar-method.

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

Sidebar

Related Questions

I am a C++ developer and recently started working on C# WPF app. I
I am a C++ developer and recently started working on WPF. Well I am
I am a C++ developer and have recently started learning WPF. I am working
I`m an Android developer, and recently started working on JAVA PC project for client.
I'm a junior developer and recently started working for a very small office where
I started a new job recently. I've been a Java & XML web developer
I recently inherited an iPhone app. The original developer did not understand memory management
I'm a front end developer who's recently started using IntelliJ Idea for JS development.
I'm a strong Java developer who has very recently started trying to pick up
I recently started developing a small app using the sample provided in this article.

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.