This is probably very simple, but Google has not helped me this time.
I have a grid defined in XAML, I want to add radiobuttons programatically. The problem I have right now is that it's adding the radiobuttons on top of each other, but google searches shows others doing the same thing.
RadioButton r1 = new RadioButton();
RadioButton r2 = new RadioButton();
Can anyone help? Thanks!
(hmm, no preview button in here..)
@pavone:You need to set the Grid.Row and Grid.Column attached properties for each radio button like so:
Thanks DCMonkey, there was something else to add to get it to work.
RowDefinition row = new RowDefinition(); // do this for number of rows
row.Height = new GridLength(20); // to get it to right size
Seems a bit convoluted, but it works.
I'm not sure what the use case is, but maybe something with stackpanel's?
Yes, I'd do this in a StackPanel instead of a Grid, depending on your layout requirements.
You may also want to think about doing this all in XAML with a ListView and a DataTemplate.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.