I am c++ developer and from last week i started working on C# and WPF. I have a very simple query about using structures in my code. I have a label and button in my xaml class which should be dynamically generated. I had developed in c++ as follows:
typedef struct
{
String ChannelName;
bool available;
} Voltage_Channel;
Voltage_Channel *m_voltageChannels;
Voltage_Channel redhookChannels[6] = {
{"", false},
{"VDD_IO_AUD", true},
{"VDD_CODEC_AUD", true},
{"VDD_DAL_AUD", true},
{"VDD_DPD_AUD", true},
{"VDD_PLL_AUD", true},
};
m_voltageChannels = redhookChannels;
int cnt = 0;
int MAX_ADC =6;
while(cnt < MAX_ADC)
{
m_labelChannel[cnt] = new Label(m_voltageChannels[cnt].ChannelName); //Generates labels based on count
m_setButton[cnt] = new TextButton("Set"); //generates Buttons based on Count
m_setButton[cnt]->addButtonListener(this); // Event for the Button
if(m_voltageChannels[cnt].available)
{
addAndMakeVisible(m_labelChannel[cnt]); //Displays if channel is available
addAndMakeVisible(m_setButton[cnt]);
}
}
This generates the label and button 6 times and if channel is available then displays it.
I have the following in my Xaml File:
<Label Grid.Column="0" Content="{Binding VoltageLabel}" Name="VoltageLabel" />
<Button Grid.Column="1" Content="Set" Command="{Binding Path=SetButtonCommand}" Name="VoltageSetbtn" />
Label and Button Property:
string voltageLabel;
public string VoltageLabel
{
get { return voltageLabel; }
set
{
voltageLabel = value;
OnPropertyChanged("VoltageLabel");
}
}
// Event for Set Button Click
private ICommand mSetCommand;
public ICommand SetButtonCommand
{
get
{
if (mSetCommand == null)
mSetCommand = new DelegateCommand(new Action(SetCommandExecuted), new Func<bool>(SetCommandCanExecute));
return mSetCommand;
}
set
{
mSetCommand = value;
}
}
public bool SetCommandCanExecute()
{
return true;
}
public void SetCommandExecuted()
{
// Body of the method
}
Is it possible to dynamically generate these controls using structures, looking at how I had done it in my C+ application???
Please help