tyleManager.SetTheme on RadDocking crashes

3 posts, 0 answers
  1. Trish
    Trish avatar
    6 posts
    Member since:
    Oct 2011

    Posted 15 Dec 2011 Link to this post

    When I try to set the theme on the RadDocking class it crashes.  The error is "Element already has a logical parent.  It must be detached from the old parent before it is attached to a new one."  See the attached screen shot.

    RadDocking Version: 2011.3.1116.40

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Persistence.Services;
    using Telerik.Windows.Persistence.Storage;
     
    namespace BasicDockingPersistenceExample
    {
     
        public partial class MainWindow : Window
        {
            private Theme _currentTheme = null;
            public MainWindow()
            {
                  this.DataContext = new MainWindowViewModel();
     
                _currentTheme = new Office_SilverTheme();
                StyleManager.ApplicationTheme = _currentTheme;
     
                InitializeComponent();
              }
     
     
     
            private void RadButton_Click(object sender, RoutedEventArgs e)
            {
                _currentTheme = new Office_BlackTheme();
                StyleManager.ApplicationTheme = _currentTheme;
                Telerik.Windows.Controls.StyleManager.SetTheme(BuildDocking, _currentTheme);
            }
     
          }
    }

    <Window x:Class="BasicDockingPersistenceExample.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    Title="MainWindow" Height="588" Width="876" Loaded="BuildDockingLoaded">
        <Window.Resources>
            <Style TargetType="{x:Type telerik:RadDocking}">
                <Setter Property="telerik:StyleManager.Theme" Value="{x:Static telerik:StyleManager.ApplicationTheme}"/>
            </Style>
            <Style TargetType="{x:Type telerik:RadDockPanel}">
                <Setter Property="telerik:StyleManager.Theme" Value="{x:Static telerik:StyleManager.ApplicationTheme}"/>
            </Style>
            <Style TargetType="{x:Type telerik:RadPane}">
                <Setter Property="telerik:StyleManager.Theme" Value="{x:Static telerik:StyleManager.ApplicationTheme}"/>
            </Style>
            <Style TargetType="{x:Type telerik:RadPaneGroup}">
                <Setter Property="telerik:StyleManager.Theme" Value="{x:Static telerik:StyleManager.ApplicationTheme}"/>
            </Style>
            <Style TargetType="{x:Type telerik:RadSplitContainer}">
                <Setter Property="telerik:StyleManager.Theme" Value="{x:Static telerik:StyleManager.ApplicationTheme}"/>
            </Style>
            <Style TargetType="{x:Type telerik:ToolWindow}">
                <Setter Property="telerik:StyleManager.Theme" Value="{x:Static telerik:StyleManager.ApplicationTheme}"/>
            </Style>
     
        </Window.Resources>
        <telerik:RadDocking x:Name="BuildDocking" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                            Padding="2"  HasDocumentHost="False"
                            telerik:PersistenceManager.StorageId="BuildDocking">
            <telerik:RadSplitContainer Orientation="Horizontal" InitialPosition="DockedBottom">
                <telerik:RadPaneGroup >
                    <telerik:RadPane x:Name="Pane1Panel" Header="Pane 1"
                                     telerik:RadDocking.SerializationTag="Pane1Panel"
                                     IsPinned="{Binding Path=Pane1PanelIsPinned, Mode=TwoWay}" CanUserClose="False" CanDockInDocumentHost="False">
     
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
            <telerik:RadSplitContainer Orientation="Horizontal" InitialPosition="DockedLeft" >
                <telerik:RadPaneGroup  telerik:ProportionalStackPanel.RelativeSize="200, 300">
                    <telerik:RadPane x:Name="Pane2Panel" Header="Pane 2"
                                     telerik:RadDocking.SerializationTag="Pane2Panel"
                                     IsPinned="{Binding Path=Pane2PanelIsPinned, Mode=TwoWay}" CanUserClose="False" CanDockInDocumentHost="False">
                        <telerik:RadButton Content="Change Theme" Click="RadButton_Click" Height="30" VerticalAlignment="Top" Margin="10"/>
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
            <telerik:RadSplitContainer Orientation="Horizontal" InitialPosition="DockedRight" MinWidth="300">
                <telerik:RadPaneGroup >
                    <telerik:RadPane Header="Pane 3" x:Name="Pane3Panel"
                                     telerik:RadDocking.SerializationTag="Pane3Panel"
                                     IsPinned="{Binding Path=Pane3PanelIsPinned, Mode=TwoWay}" CanUserClose="False" CanDockInDocumentHost="False" >
     
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
            <telerik:RadSplitContainer Orientation="Vertical" InitialPosition="DockedTop"  MinHeight="100" >
                <telerik:RadPaneGroup >
                    <telerik:RadPane Header="Pane 4" x:Name="Pane4Panel" 
                                     telerik:RadDocking.SerializationTag="Pane4Panel"
                                     IsPinned="{Binding Path=Pane4PanelIsPinned, Mode=TwoWay}"  CanUserClose="False" CanDockInDocumentHost="False" >
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
            <telerik:RadSplitContainer Orientation="Vertical" InitialPosition="DockedTop"  MinHeight="100" >
                <telerik:RadPaneGroup >
                    <telerik:RadPane Header="Pane 5" x:Name="Pane5Panel"
                                     telerik:RadDocking.SerializationTag="Pane5Panel"
                                     IsPinned="{Binding Path=Pane5PanelIsPinned, Mode=TwoWay}" CanUserClose="False" CanDockInDocumentHost="False" >
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
     
        </telerik:RadDocking>
     
    </Window>

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
     
    namespace BasicDockingPersistenceExample
    {
        public class MainWindowViewModel : INotifyPropertyChanged
        {
            public MainWindowViewModel()
            {
                 
            }
     
            #region DockPanel pinning properties
     
            private bool? _pane2PanelIsPinned = true;
     
            public bool? Pane2PanelIsPinned
            {
                get { return _pane2PanelIsPinned; }
                set
                {
                    _pane2PanelIsPinned = value;
                    FirePropertyChanged("Pane2PanelIsPinned");
                }
            }
     
            private bool? _pane1PanelIsPinned = false;
     
            public bool? Pane1PanelIsPinned
            {
                get { return _pane1PanelIsPinned; }
                set
                {
                    _pane1PanelIsPinned = value;
                    FirePropertyChanged("Pane1PanelIsPinned");
                }
            }
     
            private bool? _pane5PanelIsPinned = false;
     
            public bool? Pane5PanelIsPinned
            {
                get { return _pane5PanelIsPinned; }
                set
                {
                    _pane5PanelIsPinned = value;
                    FirePropertyChanged("Pane5PanelIsPinned");
                }
            }
     
            private bool? _pane3PanelIsPinned = true;
     
            public bool? Pane3PanelIsPinned
            {
                get { return _pane3PanelIsPinned; }
                set
                {
                    _pane3PanelIsPinned = value;
                    FirePropertyChanged("Pane3PanelIsPinned");
                }
            }
     
            private bool? _pane4PanelIsPinned = true;
     
            public bool? Pane4PanelIsPinned
            {
                get { return _pane4PanelIsPinned; }
                set
                {
                    _pane4PanelIsPinned = value;
                    FirePropertyChanged("Pane4PanelIsPinned");
                }
            }
     
            #endregion
     
     
            public event PropertyChangedEventHandler PropertyChanged;
     
            protected void FirePropertyChanged(string property)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
     
        }
    }






  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 20 Dec 2011 Link to this post

    Hello Trish,

    I can suggest you a better approach for changing the theme in WPF for the Docking control. Put the whole Docking control in a Frame and on the button click apply the theme and refresh the frame:

    StyleManager.ApplicationTheme = new Office_BlackTheme();
    frame1.Refresh();

    Kind regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
    Kind regards,the Telerik team
  3. UI for WPF is Visual Studio 2017 Ready
  4. Trish
    Trish avatar
    6 posts
    Member since:
    Oct 2011

    Posted 20 Dec 2011 Link to this post

    Never mind...
Back to Top