我是一名C++开发人员,最近转向了C#。我正在开发一个WPF应用程序,在其中需要动态生成4个单选按钮。我尝试进行了大量研究和开发,但似乎这种情况很少见。
XAML:
现在这里是情景:我需要生成这个单选按钮4次,并且使用不同的
如果您注意到上面的内容,每次for循环运行时Content的名称会变为
我该如何在我的WPF应用程序中实现这一点? :)
<RadioButton Content="Base 0x" Height="16" Name="radioButton1" Width="80" />
现在这里是情景:我需要生成这个单选按钮4次,并且使用不同的
内容
,如下所示:<RadioButton Content = Base 0x0 />
<RadioButton Content = Base 0x40 />
<RadioButton Content = Base 0x80 />
<RadioButton Content = Base 0xc0 />
我在我的C++应用程序中已经完成了以下操作:
#define MAX_FPGA_REGISTERS 0x40;
for(i = 0; i < 4; i++)
{
m_registerBase[i] = new ToggleButton(String(T("Base 0x")) + String::toHexString(i * MAX_FPGA_REGISTERS));
addAndMakeVisible(m_registerBase[i]);
m_registerBase[i]->addButtonListener(this);
}
m_registerBase[0]->setToggleState(true);
如果您注意到上面的内容,每次for循环运行时Content的名称会变为
Base 0x0
、Base 0x40
、base 0x80
和base 0xc0
,并将第一个单选按钮的切换状态设置为true。因此,如果您注意到,这四个按钮将拥有单一的点击方法,并且根据索引执行相应操作。我该如何在我的WPF应用程序中实现这一点? :)