我是C++開發者和上週我開始在C#和WPF工作動態生成的UI組件。我有一個關於在我的代碼中使用結構的非常簡單的查詢。我的xaml類中有一個標籤和按鈕,應該是動態生成的。我用C++開發如下:使用結構數組在C#
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]);
}
}
這將生成標籤和按鈕6次,如果通道可用,然後顯示它。
我在XAML中文件如下:
<Label Grid.Column="0" Content="{Binding VoltageLabel}" Name="VoltageLabel" />
<Button Grid.Column="1" Content="Set" Command="{Binding Path=SetButtonCommand}" Name="VoltageSetbtn" />
標籤和按鈕屬性:
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
}
是否有可能使用結構這些控件,看如何動態生成我在我的C +應用程序中完成了它?
請幫
除了:在Windows 8上開發時,您也可以使用C++的XAML。你爲什麼使用C#? – Beachwalker
@Stegi:我沒有爲Windows 8開發。我在我的C++代碼中使用了JUCE,我必須在WPF中做同樣的事情:) – StonedJesus