This is a migrated thread and some comments may be shown as answers.

Setting content dynamically

1 Answer 93 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Mrn asked on 07 Jun 2011, 12:11 PM

Is it possible to set the content of an Expander in code behind? For example, a certain grid or stackpanel with its own children controls... something like this:

<telerik:RadExpander Grid.Row="0" Header="{Binding Strings.Parameters, Source={StaticResource LocalizedStrings}}" Name="radExpanderParameters" Width="Auto" IsExpanded="True" >
                       <Grid Name="gridType" Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" ShowGridLines="False">
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="2*" />
                                <StackPanel Grid.Row="0" Margin="10" VerticalAlignment="Center">
                                    <RadioButton Margin="3" Content="Type 1" Height="16" GroupName="QueryType" x:Name="radioButton1"
                                                IsChecked="{Binding QueryType, Mode=TwoWay, ConverterParameter=current, Converter={StaticResource RadioButtonConverter}}" />
                                    <RadioButton Margin="3" Content="Type 2" Height="16" GroupName="QueryType" Name="radioButton2"
                                                IsChecked="{Binding QueryType, Mode=TwoWay, ConverterParameter=historical, Converter={StaticResource RadioButtonConverter}}" />
                                    <RadioButton Margin="3" Content="Type 3" Height="16" GroupName="QueryType" Name="radioButton3"
                                                IsChecked="{Binding QueryType, Mode=TwoWay, ConverterParameter=prediction, Converter={StaticResource RadioButtonConverter}}" />
                                <StackPanel Grid.Row="1" Margin="10">

but I'd like to set the Grid in code behind instead.

Thanks in advance!

1 Answer, 1 is accepted

Sort by
Petar Mladenov
Telerik team
answered on 10 Jun 2011, 02:05 PM
Hi Mrn,

Evrything that is possible is XAML is possible in code behind. The opposite is not true.
Your code from xaml should be similar to this C#:
private void BuildExpanderOnTheFly()
    RadExpander expander = new RadExpander();
    Grid grid = new Grid();
    grid.VerticalAlignment = VerticalAlignment.Stretch;
    grid.ShowGridLines = false;
    grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) { } });
    grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2, GridUnitType.Star) { } });
    StackPanel panel = new StackPanel();
    RadRadioButton button = new RadRadioButton() { IsChecked = true, Content="Buuuuuton" };
    expander.Content = grid;

All the best,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question