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

Programatically expanding given item

3 Answers 153 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 16 May 2011, 12:27 PM
Hot to programatically expand some item? I would like to do something like:
Items[0].Items[4].Expand()

I know there is a method called ExpandItemByPath but i cannot guess how to use it and documentation says absolutely nothing about it.

Thanks in advance for any help

3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 18 May 2011, 03:09 PM
Hi Ivan,

You can try the following approach:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Button Content="Expand" Click="Expand_Click" />
    <telerik:RadPanelBar x:Name="panelBar1" Grid.Row="1">
        <telerik:RadPanelBarItem Header="Item 1">
            <telerik:RadPanelBarItem Header="Item 1.1">
                <telerik:RadPanelBarItem Header="Item 1.1.1" />
            </telerik:RadPanelBarItem>
        </telerik:RadPanelBarItem>
    </telerik:RadPanelBar>
</Grid>

private void Expand_Click(object sender, RoutedEventArgs e)
{
    var item = this.panelBar1.Items[0] as RadPanelBarItem;
    item.IsExpanded = true;
    var subItem = item.Items[0] as RadPanelBarItem;
    subItem.IsExpanded = true;
}

Let me know how it goes.

All the best,
Kiril Stanoev
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
0
Ivan
Top achievements
Rank 1
answered on 19 May 2011, 09:20 AM
Hi Kiril,

this solution won't work, as
this.radPanelBar.Items[0] is of type CommandViewModel (we are binding collection of viewmodels for ItemsSource of radpanel)
0
Kiril Stanoev
Telerik team
answered on 24 May 2011, 12:35 PM
Hello Ivan,

Thanks for the clarification. Another approach is to expand/collapse using a property within the ViewModel. This can easily be achieved using a binding within the ItemContainerStyle of RadPanelBar:

<telerik:RadPanelBar x:Name="panelBar1">
    <telerik:RadPanelBar.ItemContainerStyle>
        <Style TargetType="telerik:RadPanelBarItem">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
        </Style>
    </telerik:RadPanelBar.ItemContainerStyle>
</telerik:RadPanelBar>

In the above example, Property="IsExpanded" is the IsExpanded property of RadPanelBarItem, whether Value="{Binding IsExpanded, Mode=TwoWay}" is the IsExpanded property of your ViewModel.

Now on a button click you can do something like this:

private void Button_Click(object sender, RoutedEventArgs e)
{
    ObservableCollection<CommandViewModel> dataSource = this.panelBar1.ItemsSource as ObservableCollection<CommandViewModel>;
    CommandViewModel level1 = dataSource[0];
    level1.IsExpanded = true;
    CommandViewModel level2 = level1.Children[0];
    level2.IsExpanded = true;
}

Please refer to the attached project for further information and let me know if this approach satisfies you.

Regards,
Kiril Stanoev
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
PanelBar
Asked by
Ivan
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Ivan
Top achievements
Rank 1
Share this question
or