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"
                                             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>
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top