Dynamic theme setting for GridView causes runtime exception

2 posts, 0 answers
  1. Pabitra
    Pabitra avatar
    7 posts
    Member since:
    Jun 2012

    Posted 26 Jun 2012 Link to this post

     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" />
  2. Ivan Ivanov
    Ivan Ivanov avatar
    1201 posts

    Posted 27 Jun 2012 Link to this post

    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 >>
Back to Top