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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:36:00+00:00 2026-06-12T20:36:00+00:00

I am a C++ developer and i recently shifted to C# WPF. I am

  • 0

I am a C++ developer and i recently shifted to C# WPF. I am working on a WPF App where I am supposed to dynamically generate button, label, textbox and togglebutton. I have done the following:

XAMl:

<ListBox x:Name="myViewChannelList" HorizontalAlignment="Stretch" Height="Auto" ItemsSource="{Binding VoltageCollection}" Margin="0" VerticalAlignment="Stretch" Width="Auto">
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170"  />
                            <ColumnDefinition />
                            <ColumnDefinition  />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <Label Grid.Column="0" Content="{Binding ChannelName}" Margin="50,20,0,0"></Label>

                        <Grid Grid.Column="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBox Grid.Column="0" Text="{Binding VoltageText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="25" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="170,20,0,0" />
                            <Button Grid.Column="1" Content="Set" Height="25" CommandParameter="{Binding VoltageText}" Command="{Binding VoltageCommand}" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20,20,0,0" ></Button>
                        </Grid>

                        <Label Grid.Column="2" Content="{Binding Path=Voltage}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="210,20,0,0" ></Label>
                        <ToggleButton Grid.Column="3" Content="On" Height="25" Width="30" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="120,20,0,0" ></ToggleButton>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

<Button Content="Redhook" Command="{Binding RedhookCommand}" FontSize="13" Height="25" HorizontalAlignment="Center" Margin="0,0,0,0" Name="Refresh1Btn" VerticalAlignment="Center" Width="105"  />

ViewModel Class:

class ChannelList : INotifyPropertyChanged
{
    private ICommand m_voltageCommand;
    public ChannelList()
{
    m_voltageCommand = new DelegateVoltageCommand(x => SetCommandExecute(x));
}

public void Initialize()
{
    VoltageCollection = new ObservableCollection<VoltageModel> { new VoltageModel() { ChannelName = "VDD__Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand }, 
                                                                 new VoltageModel() { ChannelName = "VDD__IO__AUD", VoltageText = String.Empty, VoltageCommand = m_voltageCommand }, 
                                                                 new VoltageModel() { ChannelName = "VDD__CODEC__AUD", VoltageText = String.Empty, VoltageCommand = m_voltageCommand } 
                                                               }; 
}

public ObservableCollection<VoltageModel> VoltageCollection { get; set; }

/// <summary>
/// Event On Get Current Frquency Button Click
/// </summary>
private ICommand mRedhookCommand;
public ICommand RedhookCommand
{
    get
    {
        if (mRedhookCommand == null)
            mRedhookCommand = new DelegateCommand(new Action(GetCurrentFreqExecuted), new Func<bool>(GetCurrentFreqCanExecute));

        return mRedhookCommand;
    }
    set
    {
        mRedhookCommand = value;
    }
}    

public bool GetCurrentFreqCanExecute()
{
    return true;
}

public void GetCurrentFreqExecuted()
{
    VoltageCollection.Clear();
    VoltageCollection = new ObservableCollection<VoltageModel> { new VoltageModel() { ChannelName = "VDD__Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand }, 
                                                                 new VoltageModel() { ChannelName = "VDD__IO__AUD", VoltageText = String.Empty, VoltageCommand = m_voltageCommand }, 
                                                                 new VoltageModel() { ChannelName = "VDD__CODEC__AUD", VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
                                                                 new VoltageModel() { ChannelName = "VDD__LDO", VoltageText = String.Empty, VoltageCommand = m_voltageCommand},
                                                                 new VoltageModel() { ChannelName = "VDD__AMP", VoltageText = String.Empty, VoltageCommand = m_voltageCommand}                                                                 
                                                               }; 
}

Thus on application startup I am able to display the dynamically generated controls. But on clicking REDHOOK button, i want to update the list with new values as mentioned in my GetCurrentFreqExecuted(). When I am trying to do this, the list gets cleared but doesnt update the new values. How can i achieve this???

  • 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-12T20:36:01+00:00Added an answer on June 12, 2026 at 8:36 pm

    The problem is, Your VoltageCollection does not notify when it’s instance is changed.
    So what you need to do is call PropertyChanged when assigning instance to the VoltageCollection.

        ObservableCollection<VoltageModel> _voltages;
        public ObservableCollection<VoltageModel> VoltageCollection {
    
         get {return voltages;}
         set 
         {
         _volgates=value;
          PropertyChanged("VoltageCollection");
    
         }
    

    Other way,

    In your GetCurrentFreqExecuted() method, do not assign an instance to the VoltageCollection. ie, Remove VoltageCollection=new ObservableCollection<>....().

    And add Each item using for each loop.

    Now your code looks like

    VoltageCollection.Clear();
        VoltageModel[] models = { new VoltageModel() { ChannelName = "VDD_Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
                                  new VoltageModel() { ChannelName = "VDD_Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
                                  new VoltageModel() { ChannelName = "VDD_Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
                                  new VoltageModel() { ChannelName = "VDD_Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
                                  new VoltageModel() { ChannelName = "VDD_Main", VoltageText = String.Empty, VoltageCommand = m_voltageCommand }
                                };
    
        foreach (var model in models)
        {
            VoltageCollection.Add(model);
        }
    
    • 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 shifted to C#. I am working on
I am a C++ developer and I recently shifted to C#. I am working
I am a C++ Developer and have recently shifted to C#. I am developing
I am a C++ developer and recently started working on WPF. Well I am
I am a .Net developer but recently shifted to PHP world. I have worked
I am a c++ developer and recently shifted to this amazing WPF world. I
I am a C++ developer and recently shifted to the world of WPF C#.
I recently inherited an iPhone app. The original developer did not understand memory management
I`m an Android developer, and recently started working on JAVA PC project for client.

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.