2
At a certain point in the software, I need to populate a DataGrid
in Runtime. I managed to perform this operation partially.
My problem is that even if I insert RadioButton.Content
, it simply does not present the past Content. Also, the Group does not work in RadioButton
.
Follow the code to facilitate understanding.
public void PovoarMacros(TabControl tcMacro)
{
for (int i = 1; i < 11; i++)
{
var tab = new TabItem();
var dg = new DataGrid();
var nomeMacroColumn = new DataGridTemplateColumn();
var descricaoMacroColumn = new DataGridTextColumn();
RadioButton radio = null;
nomeMacroColumn.Header = "Macro";
nomeMacroColumn.Width = 438;
nomeMacroColumn.CanUserResize = false;
nomeMacroColumn.CanUserReorder = false;
var template = new DataTemplate();
var rbFramework = new FrameworkElementFactory(typeof(RadioButton));
rbFramework.SetBinding(ToggleButton.IsCheckedProperty, new Binding("rb"));
template.VisualTree = rbFramework;
nomeMacroColumn.CellTemplate = template;
nomeMacroColumn.IsReadOnly = true;
descricaoMacroColumn.Header = "Descricao";
descricaoMacroColumn.Width = 438;
descricaoMacroColumn.CanUserResize = false;
descricaoMacroColumn.CanUserReorder = false;
descricaoMacroColumn.Binding = new Binding("descricao");
descricaoMacroColumn.IsReadOnly = true;
dg.Columns.Add(nomeMacroColumn);
dg.Columns.Add(descricaoMacroColumn);
for (int j = 0; j < vetor.getVetor(i).Length; j++)
{
var macro = (vetor.getVetor(i))[j];
radio = new RadioButton();
radio.Content = macro[0];
radio.GroupName = vetor.getNomeVetor(i);
dg.Items.Add(new Linha() { rb = radio, descricao = macro[1] });
}
tab.Header = vetor.getNomeVetor(i);
tab.Content = dg;
tcMacro.Items.Add(tab);
}
}