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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:29:16+00:00 2026-06-13T01:29:16+00:00

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

  • 0

I am a C++ developer and I recently shifted to C#. I am working on a wpf app where I have to dynamically generate button, labels and textbox. Along with dynamically generating them, I have made sure only those channels must be displayed which are available by maintaining a bool available property. Here is the code:

XAML:

<Grid Visibility="{Binding IsAvailable, Converter={StaticResource booltovisibility}}">          

    <Label Grid.Column="0" Content="{Binding ChannelName}" />
    <TextBox Grid.Column="1" Text="{Binding VoltageText}" PreviewTextInput="VoltageBox_PreviewTextInput"  />
    <Button Grid.Column="1" Content="Set" CommandParameter="{Binding}" Command="{Binding VoltageCommand}" />
    <Label Grid.Column="2" Content="{Binding CurrentText}" />
    <ToggleButton Grid.Column="3" Content="On" Command="{Binding VoltageToggleCommand}" IsChecked="{Binding Path=IsChecked}" />
</Grid>

    <Button Content="Refresh All" Grid.Column="1" Command="{Binding Path=RefreshAllButtonCommand}" Name="RefreshAllBtn" />

ViewModel:

public ObservableCollection<VoltageBoardChannel> channelList = null;
public ObservableCollection<VoltageBoardChannel> bavaria1Channels = new ObservableCollection<VoltageBoardChannel>
    {
         new VoltageBoardChannel { ChannelName = "VDD__MAIN", IsAvailable = true, ID = 1},
         new VoltageBoardChannel { ChannelName = "VDD__IO", IsAvailable = true, ID = 2},
         new VoltageBoardChannel { ChannelName = "VDD__CODEC", IsAvailable = true, ID = 3},
         new VoltageBoardChannel { ChannelName = "VDD__LDO", IsAvailable = true, ID = 4},
         new VoltageBoardChannel { ChannelName = "VDD__AMP", IsAvailable = true, ID = 5},   
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 6}, 
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 7}, 
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 8}, 
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 9}, 
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 10}, 
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 11}, 
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 12}, 
    };        

    public VoltageViewModel()
    {
        channelList = new ObservableCollection<VoltageBoardChannel>();
        channelList = bavaria1Channels;         

    }
public ObservableCollection<VoltageBoardChannel> VoltageChannelList
    {
        get 
        { 
            return channelList; 
        }

        set
        { 
            channelList = value;
            OnPropertyChanged("ChannelList");
        }
    }

void RefreshAllClick()
{
    //Here I want to check if channel are available or not. If yes then execute few statements.
}

Model Class:

private string mChannelName;
    public string ChannelName
    {
        get
        {
            return mChannelName;
        }
        set
        {
            mChannelName = value;
            OnPropertyChanged("ChannelName");
        }
    }

    private bool mIsAvailable;
    public bool IsAvailable
    {
        get
        {
            return mIsAvailable;
        }
        set
        {
            mIsAvailable = value;
            OnPropertyChanged("IsAvailable");
        }
    }

    double voltageText;
    public double VoltageText
    {
        get
        {
            return voltageText;
        }

        set
        {
            if (value > 5.0D || value < 0.0D)
                throw new InvalidOperationException();
            voltageText = value;
            OnPropertyChanged("VoltageText");
        }
    }

    string currentText = "0";
    public string CurrentText
    {
        get
        {
            return currentText + " V";                
        }

        set
        {
            currentText = value;
            OnPropertyChanged("CurrentText");
        }
    }          

    int index ;
    public int ID
    {
        get
        {
            return index;
        }

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

Thus if you notice in my Bavaria1 Channel you will find few channels are available(true) and few are false. Thus on startup it displays only the Available channels. Thus using booltovisibility class I am able to set the visibility in my grid and display accordingly Now here is what I want to achieve:

When I click RefreshAll Button, a method called RefreshAll_Click() is triggered and I want to check in a if condition which channels are available. If yes then execute few statements. I had done this in C++ as follows:

if(m_voltageChannels[channel].available) // Here channel is 12 as you can notice in bavaria1 list
{
    cmd = (0x8400 | (channel & 0xFF));  

    String OldValue = m_labelCurrentVoltage[channel]->getText();
            //Some Code
    }

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-13T01:29:18+00:00Added an answer on June 13, 2026 at 1:29 am

    I would use a foreach loop, or linq. Since you’re starting out in C#, here’s the foreach approach:

    void RefreshAllClick() 
    {
        foreach (var channel in channelList)
            if (channel.IsAvailable)
                //some code here 
    } 
    

    Or, since ObservableCollection<T> implements IList<T>, you can index into the collection, as in your C++ code:

    if (channelList[channel].IsAvailable)
        //some code here
    

    If you just need a boolean that is true iff at least one channel is available, linq is best:

    var anyChannelIsAvailable = channelList.Any(c => c.IsAvailable);
    

    Moved from my previous (now deleted) comment, here’s some unsolicited further advice:

    You should remove the line channelList = new ObservableCollection<VoltageBoardChannel>();, since you’re immediately discarding that object by reassigning the reference in the next line (channelList = bavaria1Channels;). In fact, you don’t need bavaria1Channels (nor the constructor) at all; you can just declare and initialize channelList with the collection initializer expression, like this:

    public ObservableCollection<VoltageBoardChannel> channelList = new ObservableCollection<VoltageBoardChannel>    
    {    
         new VoltageBoardChannel { ChannelName = "VDD__MAIN", IsAvailable = true, ID = 1},    
         new VoltageBoardChannel { ChannelName = "VDD__IO", IsAvailable = true, ID = 2},    
         new VoltageBoardChannel { ChannelName = "VDD__CODEC", IsAvailable = true, ID = 3},    
         new VoltageBoardChannel { ChannelName = "VDD__LDO", IsAvailable = true, ID = 4},    
         new VoltageBoardChannel { ChannelName = "VDD__AMP", IsAvailable = true, ID = 5},       
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 6},     
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 7},     
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 8},     
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 9},     
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 10},     
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 11},     
         new VoltageBoardChannel { ChannelName = "", IsAvailable = false, ID = 12},     
    };            
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a .Net developer but recently shifted to PHP world. I have worked
I am a C++ developer and i recently shifted to C# WPF. I am
I am a C++ developer and recently shifted to C#. I am working on
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 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 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.
I am an android app developer, recently I am trying to learn Marmalade to

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.