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

Dynamic theme setting for GridView causes runtime exception

1 Answer 86 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Pabitra asked on 26 Jun 2012, 03:11 PM
 Here is the code where the theme for the GirdView is bound to the ViewModel's SelectedTheme property. The problem is with the custom header column that includes a checkbox. The UI has a combobox that allows the user to select a theme which is bound to the SelectedTheme property of the viewmodel. When I try to change the theme, I get the following exception:

Specified element is already the logical child of another element. Disconnect it first.

 If I comment out the section
<telerik:GridViewCheckBoxColumn.Header> from the code then it is fine. I don't get any exception when dynamically setting the theme for the gridview.

<telerik:RadGridView Name="radGridView"
                                         telerik:StyleManager.Theme="{Binding SelectedTheme}">
                            <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsSelected, Mode=TwoWay}"
                                <telerik:GridViewCheckBoxColumn.Header><!--this part throws exception if gridview is bound to the vm's theme property-->
                                    <StackPanel Orientation="Horizontal">
                                        <CheckBox Name="chkAllSelect"
                                                  IsChecked="{Binding AreAllSelected, Mode=TwoWay}" /> <!--this binding seems not possible-->
                                        <TextBlock Text="Select"
                                                   Margin="5,0,3,0" />

1 Answer, 1 is accepted

Sort by
Ivan Ivanov
Telerik team
answered on 27 Jun 2012, 12:08 PM
Hello Pabitra,

For scenarios where theme-switching is involved, it is recommended to utilize our new implicit-style-based mechanism. Here is a detailed article that illustrates how to achieve this.

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Asked by
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question