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
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>