At some point in the software, I need to populate a DataGrid
in runtime. I was able to perform this operation partially.
My problem is that even though I enter RadioButton.Content
, it just does not display past content. Also, Group does not work in RadioButton
.
Follow the code to make it easier to understand.
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);
}
}