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

Setting content dynamically

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

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">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="2*" />
                                 </Grid.RowDefinitions>
  
                                <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>
  
                                <StackPanel Grid.Row="1" Margin="10">
                                </StackPanel>
  
                        </Grid>
                    </telerik:RadExpander>

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

Thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Accepted
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" };
    panel.Children.Add(button);
    grid.Children.Add(panel);
    expander.Content = grid;
    this.LayoutRoot.Children.Add(expander);
}



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
Tags
Expander
Asked by
Mrn
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or