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

Dynamic theme setting for GridView causes runtime exception

1 Answer 51 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Pabitra
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"
                                         SelectionMode="Extended"
                                         EnableRowVirtualization="True"
                                         FrozenColumnCount="1"
                                         AlternationCount="2"
                                         AutoGenerateColumns="False"
                                         telerik:StyleManager.Theme="{Binding SelectedTheme}">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsSelected, Mode=TwoWay}"
                                                            EditTriggers="CellClick"
                                                            AutoSelectOnEdit="True">
 
                                <telerik:GridViewCheckBoxColumn.Header><!--this part throws exception if gridview is bound to the vm's theme property-->
                                    <StackPanel Orientation="Horizontal">
                                        <CheckBox Name="chkAllSelect"
                                                  VerticalAlignment="Center"
                                                  Click="chkAllSelect_Click"                                                  
                                                  IsChecked="{Binding AreAllSelected, Mode=TwoWay}" /> <!--this binding seems not possible-->
                                        <TextBlock Text="Select"
                                                   VerticalAlignment="Center"
                                                   Margin="5,0,3,0" />
                                    </StackPanel>
                                </telerik:GridViewCheckBoxColumn.Header> 
                            </telerik:GridViewCheckBoxColumn>                            
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
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 >>
Tags
Chart
Asked by
Pabitra
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or