SaveLayout when isHidden is binding

7 posts, 0 answers
  1. Aurore
    Aurore avatar
    58 posts
    Member since:
    Nov 2007

    Posted 24 Nov 2011 Link to this post

    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




  2. Aurore
    Aurore avatar
    58 posts
    Member since:
    Nov 2007

    Posted 24 Nov 2011 Link to this post

    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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 29 Nov 2011 Link to this post

    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 >>
  5. Aurore
    Aurore avatar
    58 posts
    Member since:
    Nov 2007

    Posted 29 Nov 2011 Link to this post

    Yes it works because your raddocking still loaded.
    I am in a special case, where raddocking is unloaded from the visualtree sometimes.

    regards
    Aurore
  6. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 01 Dec 2011 Link to this post

    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 >>
  7. Itamar
    Itamar avatar
    5 posts
    Member since:
    Aug 2011

    Posted 20 Dec 2011 Link to this post

    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
  8. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 21 Dec 2011 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready