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

SaveLayout when isHidden is binding

6 Answers 189 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Aurore
Top achievements
Rank 1
Aurore asked on 24 Nov 2011, 09:14 AM
Hello,

I tried to use Savelayout/loadlayout to keep docking's layout, when in my wpf application i change "environment".
In my application I have different xaml page with each one contains a docking. And i load one or another with command in a ribbon.
Well, when an "environment" is unloaded, i'd like to keep the layout in order to redisplay it in the next control loading.

One of my environment is structured like this :
<UserControl x:Class="SphinxV6.Data.MC_Table"
    xmlns:win="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
    xmlns:v6="clr-namespace:SphinxV6" xmlns:v6Table="clr-namespace:SphinxV6.Data.Table"
    xmlns:v6Properties="clr-namespace:SphinxV6.Properties"
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
             xmlns:v6Ribbon="clr-namespace:SphinxV6.Ribbon" xmlns:toolselements="clr-namespace:SphinxV6.ToolsElements" xmlns:tabletoolselements="clr-namespace:SphinxV6.Data.Table.ToolsElements" Unloaded="UserControl_Unloaded"
             DataContextChanged="UserControl_DataContextChanged" Loaded="UserControl_Loaded">
 
    <Grid x:Name="root" DataContext="{Binding}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
 
          <telerik:RadDocking x:Name="xDocking" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HasDocumentHost="true" Unloaded="RadDocking_Unloaded"
                            v6:RadDockingExtensions.SaveFloatingPane="True"
                            telerik:RadDocking.SerializationTag="xDocking" >
            <telerik:RadDocking.CompassStyle>
                <Style TargetType="{x:Type telerik:Compass}">
                    <Setter Property="IsCenterIndicatorVisible" Value="True"/>
                </Style>
            </telerik:RadDocking.CompassStyle>
 
            <telerik:RadDocking.DocumentHost>
                <win:WindowsFormsHost Name="windowsFormsHost1" />
            </telerik:RadDocking.DocumentHost>
 
            <telerik:RadSplitContainer InitialPosition="DockedLeft" Orientation="Vertical" Width="250" telerik:RadDocking.SerializationTag="DockedLeft">
 
                <telerik:RadPaneGroup  telerik:RadDocking.SerializationTag="gVars">
                    <telerik:RadPane DataContext="{Binding DataContext.TE_Variables, ElementName=root}" Header="{Binding Title}" CanDockInDocumentHost="False" CanUserClose="False" ContextMenuTemplate="{x:Null}"
                                     telerik:RadDocking.SerializationTag="pVars">
                        <tabletoolselements:TE_VariablesControl />
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
 
                <telerik:RadPaneGroup telerik:ProportionalStackPanel.RelativeSize="200,35" telerik:RadDocking.SerializationTag="gSample">
                    <telerik:RadPane DataContext="{Binding DataContext.TE_Samples, ElementName=root}" Header="{Binding Title}" IsHidden="{Binding DataContext.IsDockSampleVisible, ElementName=root, Mode=TwoWay, Converter={StaticResource convInverseBoolean}}" CanDockInDocumentHost="False" ContextMenuTemplate="{x:Null}"
                                     telerik:RadDocking.SerializationTag="pSample">
                        <toolselements:TE_SamplesControl />
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
                <telerik:RadPaneGroup telerik:ProportionalStackPanel.RelativeSize="200,15" telerik:RadDocking.SerializationTag="gLang">
                    <telerik:RadPane DataContext="{Binding DataContext, ElementName=root}" Header="{x:Static v6Properties:Resources.languages}" CanDockInDocumentHost="False" CanUserClose="True" IsHidden="{Binding IsDockLangVisible, Mode=TwoWay, Converter={StaticResource convInverseBoolean}}" ContextMenuTemplate="{x:Null}"
                                     telerik:RadDocking.SerializationTag="pLang">
                        <StackPanel Margin="3" Orientation="Horizontal">
                            <v6:Ctrl_LangSelector ></v6:Ctrl_LangSelector>
                        </StackPanel>
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking>
    </Grid>
</UserControl>

I make "pSample" pane floattable, and change environment, here's the layout saving (which seems to be ok, as far as i understand what saving should make):
<?xml version="1.0" encoding="utf-8"?><RadDocking SerializationTag="xDocking"><SplitContainers><RadSplitContainer SerializationTag="DockedLeft" Dock="DockedLeft" Width="250" Orientation="Vertical"><Items><RadPaneGroup SerializationTag="gVars" SelectedIndex="0"><Items><RadPane SerializationTag="pVars" IsDockable="True" Title="Variables" Header="Variables" CanUserClose="False" CanDockInDocumentHost="False" /></Items></RadPaneGroup><RadPaneGroup SerializationTag="gSample" RelativeWidth="200" RelativeHeight="35" SelectedIndex="-1"><Items /></RadPaneGroup><RadPaneGroup SerializationTag="gLang" RelativeWidth="200" RelativeHeight="15" SelectedIndex="-1"><Items><RadPane SerializationTag="pLang" IsHidden="True" IsDockable="True" Title="Langues" Header="Langues" CanUserClose="True" CanDockInDocumentHost="False" /></Items></RadPaneGroup></Items></RadSplitContainer><RadSplitContainer InitialPosition="FloatingDockable" FloatingWidth="220" FloatingHeight="300" FloatingX="628" FloatingY="555" IsInOpenWindow="True" RelativeWidth="200" RelativeHeight="35" IsAutoGenerated="True"><Items><RadPaneGroup RelativeWidth="200" RelativeHeight="35" IsAutoGenerated="True" SelectedIndex="0"><Items><RadPane SerializationTag="pSample" IsHidden="False" IsDockable="True" Title="Strates" Header="Strates" CanDockInDocumentHost="False" /></Items></RadPaneGroup></Items></RadSplitContainer></SplitContainers></RadDocking>

Now, I reload my environment, the layout is well reload (my psample still flotting at the right place).
I close the pSample pane (the binding boolean is well modified).
the saved layout seems not good, "psample" appears twice ! :
<?xml version="1.0" encoding="utf-8"?><RadDocking SerializationTag="xDocking"><SplitContainers><RadSplitContainer SerializationTag="DockedLeft" Dock="DockedLeft" Width="250" Orientation="Vertical"><Items><RadPaneGroup SerializationTag="gVars" SelectedIndex="0"><Items><RadPane SerializationTag="pVars" IsDockable="True" Title="Variables" Header="Variables" CanUserClose="False" CanDockInDocumentHost="False" /></Items></RadPaneGroup><RadPaneGroup SerializationTag="gSample" RelativeWidth="200" RelativeHeight="35" SelectedIndex="-1"><Items /></RadPaneGroup><RadPaneGroup SerializationTag="gLang" RelativeWidth="200" RelativeHeight="15" SelectedIndex="-1"><Items><RadPane SerializationTag="pLang" IsHidden="True" IsDockable="True" Title="Langues" Header="Langues" CanUserClose="True" CanDockInDocumentHost="False" /></Items></RadPaneGroup></Items></RadSplitContainer>
<RadSplitContainer InitialPosition="FloatingDockable" FloatingWidth="220" FloatingHeight="300" FloatingX="649" FloatingY="514" IsInOpenWindow="False" RelativeWidth="200" RelativeHeight="35" IsAutoGenerated="True"><Items><RadPaneGroup RelativeWidth="200" RelativeHeight="35" IsAutoGenerated="True" SelectedIndex="-1"><Items><RadPane SerializationTag="pSample" IsHidden="True" IsDockable="True" Title="Strates" Header="Strates" CanDockInDocumentHost="False" /></Items></RadPaneGroup></Items></RadSplitContainer>
<RadSplitContainer InitialPosition="FloatingDockable" FloatingWidth="220" FloatingHeight="300" FloatingX="649" FloatingY="514" IsInOpenWindow="False" RelativeWidth="200" RelativeHeight="35" IsAutoGenerated="True"><Items><RadPaneGroup RelativeWidth="200" RelativeHeight="35" IsAutoGenerated="True" SelectedIndex="-1"><Items><RadPane SerializationTag="pSample" IsHidden="True" IsDockable="True" Title="Strates" Header="Strates" CanDockInDocumentHost="False" /></Items></RadPaneGroup></Items></RadSplitContainer></SplitContainers></RadDocking>

What's wrong ? And an other problem, is that  hidden floatting panes  appear on the next environment...
The workaround (you've preconise on other forum) is to use "removefromparent" function, but,
1. when i use the tip on "close pane event", then the next saving layout xml doesn't contain the "pSample" pane. (and i loose it last position)
or 2. if i remove after saving layout, i have further problem to re-display the pane (i should click several time on my check box) I obtain the following error :
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=IsDockSampleVisible; DataItem='TableEnvironment' (HashCode=18777961); target element is 'CheckBox' (Name='cbSamples'); target property is 'IsChecked' (type 'Nullable`1') TargetInvocationException:'System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel. ---> System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel. ---> System.InvalidOperationException: L'élément possède déjà un parent logique. Il doit être détaché de l'ancien parent avant d'être attaché au nouveau.
   Ã  MS.Internal.Controls.InnerItemCollectionView.AssertPristineModelChild(Object item)
   Ã  MS.Internal.Controls.InnerItemCollectionView.Insert(Int32 index, Object item)
   Ã  System.Windows.Controls.ItemCollection.Insert(Int32 insertIndex, Object insertItem)
   Ã  Telerik.Windows.Controls.RadPaneGroup.ShowSinglePane(RadPane pane)
   Ã  Telerik.Windows.Controls.RadPaneGroup.ShowPane(RadPane pane)
   Ã  Telerik.Windows.Controls.RadDocking.OnPaneShow(RadPane pane)
   Ã  Telerik.Windows.Controls.RadDocking.OnRadPaneShow(Object sender, StateChangeCommandEventArgs args)
   --- Fin de la trace de la pile d'exception interne ---
   Ã  System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   Ã  System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   Ã  System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   Ã  System.Delegate.DynamicInvokeImpl(Object[] args)
   Ã  System.Windows.RoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   Ã  System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   Ã  System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   Ã  System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   Ã  System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   Ã  System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   Ã  Telerik.Windows.Controls.RadPane.OnShow(StateChangeCommandEventArgs args)
   Ã  Telerik.Windows.Controls.RadPane.Show()
   Ã  Telerik.Windows.Controls.RadPane.OnIsHiddenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   Ã  System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   Ã  System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   Ã  System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   Ã  System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   Ã  System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
   Ã  System.Windows.Data.BindingExpression.Invalidate(Boolean isASubPropertyChange)
   Ã  System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   Ã  System.Windows.Data.BindingExpression.ScheduleTransfer(Boolean isASubPropertyChange)
   Ã  MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
   Ã  MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
   Ã  MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(Object o, String propName)
   Ã  MS.Internal.Data.PropertyPathWorker.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
   Ã  System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
   Ã  System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object sender, PropertyChangedEventArgs args)
   Ã  SphinxV6.EnvironmentBase.RaisePropertyChangedEvent(String sPropertyName) dans C:\dvlp\Project\WPF4\SphinxV6\_Common\Bases\EnvironmentBase.cs:ligne 1830
   Ã  SphinxV6.EnvironmentBase.set_IsDockSampleVisible(Boolean value) dans C:\dvlp\Project\WPF4\SphinxV6\_Common\Bases\EnvironmentBase.cs:ligne 73
   --- Fin de la trace de la pile d'exception interne ---
   Ã  System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   Ã  System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   Ã  System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   Ã  System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   Ã  System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   Ã  System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   Ã  MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
   Ã  MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
   Ã  System.Windows.Data.BindingExpression.UpdateSource(Object value)'

Well, all seems to behave as expected until i hide panes.
(in another control, i hide a pane which is in a radgroup (non flotting), but in the saved xml, the ishidden attribute stays at "false"., then when i reload the control, the pane is shown.)

Thanks for your future explanation.

Aurore

i use wpf, 2011.3.1116.35 version of telerik dll




6 Answers, 1 is accepted

Sort by
0
Aurore
Top achievements
Rank 1
answered on 24 Nov 2011, 10:15 AM
I try the following :
   - I don't use binding on IsHidden.
  - I add a close event on my docking :
private void xDocking_Close(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
       {
           foreach (RadPane oPane in e.Panes)
           {
               if (!bWorkAround && oPane.Name == "pSample") DataContextTable.IsDockSampleVisible = false;
           }
       }

  - I add a command on my checkbox display :
private void ExecutedDisplayPanesCommand(object sender, ExecutedRoutedEventArgs e)
       {
           try
           {
               pSample.IsHidden = !DataContextTable.IsDockSampleVisible;
           }
           catch
           {
               bWorkAround = true;
               pSample.IsHidden = DataContextTable.IsDockSampleVisible;
               pSample.IsHidden = !DataContextTable.IsDockSampleVisible;
               bWorkAround = false;
           }
       }
I need to use this trick because I obtain the following error message :
  {"The element already has a logical parent. It must be detached from the old parent before being attached to the new."}

Aurore

0
Konstantina
Telerik team
answered on 29 Nov 2011, 09:51 AM
Hello Aurore,

Could you please review the attached sample project, in which is illustrated how to bind the IsHidden property and Save/Load the layout correctly, and let us know if you still experience difficulties.

Regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Aurore
Top achievements
Rank 1
answered on 29 Nov 2011, 05:53 PM
Yes it works because your raddocking still loaded.
I am in a special case, where raddocking is unloaded from the visualtree sometimes.

regards
Aurore
0
Konstantina
Telerik team
answered on 01 Dec 2011, 09:31 AM
Hi Aurore,

Did you manage to resolve the issue? I am not quite sure I understand the problem. Could you please give us some more details about your scenario or ideally send us a sample project in which we can observe the issue. In that way we will be able to provide you with a solution in a timely manner.

Best wishes,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Itamar
Top achievements
Rank 1
answered on 20 Dec 2011, 10:15 AM
Hi,
I'm facing the same problem. (Use the dlls of the latest version.)
Try this scenario: Set a floating pane's IsHidden property to true by pressing the tool window's x button and execute the SaveLayout method.
(You'll see that in the generated xml the floating pane was added twice.)
Then execute the LoadLayout method and set the floating pane's IsHidden property to false (for showing the hidden floating pane). 
As Aurore mentioned previously the following exception is thrown: "The element already has a logical parent. It must be detached from the old parent before being attached to the new"
The workaround he provided works fine but this issue should be fixed on your part.

Thanks,
Itamar
0
Konstantina
Telerik team
answered on 21 Dec 2011, 03:39 PM
Hello Itamar,

This issue is fixed in the current official version of the controls available for download, i.e. Q3 2011 SP1.

Regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Docking
Asked by
Aurore
Top achievements
Rank 1
Answers by
Aurore
Top achievements
Rank 1
Konstantina
Telerik team
Itamar
Top achievements
Rank 1
Share this question
or