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

[Q2] RadPane ElementName Binding

14 Answers 120 Views
Docking
This is a migrated thread and some comments may be shown as answers.
JC
Top achievements
Rank 1
JC asked on 19 Jul 2011, 10:20 AM
Hello,

I passed to the Q2 yesterday and I my old code does no longer work !

<Grid>
 <Grid.RowDefinitions>
   <RowDefinition Height="Auto"/>
   <RowDefinition Height="Auto" />  <!--header-->
   <RowDefinition Height="*" />     <!--content-->
 </Grid.RowDefinitions>
 <tlk:RadRadioButton Grid.Row="1" x:Name="_btnAdmin" />
 <tlk:RadDocking Grid.Row="2" HasDocumentHost="False">
   <tlk:RadSplitContainer InitialPosition="FloatingDockable">
     <tlk:RadPaneGroup>
       <tlk:RadPane CanUserClose="False" CanFloat="True" CanUserPin="True" CanDockInDocumentHost="False" >  
 
<!-- Binding not work !! -->
<Buttton Visibility="{Binding IsChecked, ElementName=_btnAdmin, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Invert}" >
 
       </tlk:RadPane>
    </tlk:RadPaneGroup>
  </tlk:RadSplitContainer>
 </tlk:RadDocking>
</Grid>

It's just a binding between a button placed on a RadPane and another out the RadDocking.

Thanks for your help

14 Answers, 1 is accepted

Sort by
0
JC
Top achievements
Rank 1
answered on 22 Jul 2011, 08:20 AM
What's up ?

:)
0
Konstantina
Telerik team
answered on 22 Jul 2011, 01:38 PM
Hi Jc,

I tried to reproduce the issue, but to no avail. Attached I am sending the project. Could you please modify it in order to reproduce the issue and send it back to us. In that way we will be able to debug it here locally and track down the source of the problem.

Looking forward to your reply.

All the best,
Konstantina
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
JC
Top achievements
Rank 1
answered on 22 Jul 2011, 03:37 PM
Hello,

The problem occurs when you have a floating panel
I modified your sample to reproduce the issue
Take a look on : 

<UserControl x:Class="Docking_TEST_SL.MainPage"
    mc:Ignorable="d"
             xmlns:alf="clr-namespace:Core.Converters"
             xmlns:local="clr-namespace:Docking_TEST_SL"
    d:DesignHeight="300" d:DesignWidth="400"
   
    <UserControl.Resources>
        <local:ViewModel x:Key="MyViewModel"/>
      <alf:BooleanToVisibilityConverter x:Name="btoV"/>
  </UserControl.Resources>
 
  <Grid x:Name="LayoutRoot" Background="White" >
    <Grid.Resources>
 
    </Grid.Resources>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
 
    <StackPanel>
      <telerik:RadRadioButton x:Name="_btnAdmin" Content="click to change" IsChecked="False" GroupName="grp" />
      <telerik:RadRadioButton Content="click to change" GroupName="grp" />
    </StackPanel>
     
    <telerik:RadDocking VerticalAlignment="Stretch" x:Name="Docking" Background="{x:Null}" Grid.Row="1"
                            BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="0,0,0,0" HasDocumentHost="False" >
      <telerik:RadSplitContainer InitialPosition="DockedRight">
            <telerik:RadPaneGroup>
              <telerik:RadPane Header="Pane 1"
                               CanUserClose="False" CanFloat="False" CanUserPin="False" CanDockInDocumentHost="False">
                <Button x:Name="button" Visibility="{Binding IsChecked}"/>
              </telerik:RadPane>
            </telerik:RadPaneGroup>
          </telerik:RadSplitContainer>
      <!--HERE if you change on "DockedRight" it works !-->
      <telerik:RadSplitContainer  InitialPosition="FloatingDockable"
                                                telerik:RadDocking.FloatingSize="200,400"
           telerik:RadDocking.FloatingLocation="50,100"
           telerik:DockingPanel.InitialSize="200,600">
        <telerik:RadPaneGroup>
          <telerik:RadPane CanUserClose="False" CanFloat="True" CanUserPin="True" CanDockInDocumentHost="False" Header="Pane 3">
            <TextBlock Text="Binded to _btnAdmin"
                           Visibility="{Binding IsChecked, Converter={StaticResource btoV}, ElementName=_btnAdmin}"/>
          </telerik:RadPane>
        </telerik:RadPaneGroup>
      </telerik:RadSplitContainer>
    </telerik:RadDocking>
 
  </Grid>
</UserControl>

using System;
using System.Windows;
using System.Windows.Data;
using System.Globalization;
using System.Collections;
 
namespace Core.Converters
{
  internal static class VisibilityHelper
  {
    public static string INVERTER_PARAMETER = "Invert";
 
    public static Visibility BoolToVisibility(object toConvert, object parameter)
    {
      bool boolValue = false;
 
      if (toConvert is bool)
        boolValue = (bool)toConvert;
      else if (toConvert is bool?)
      {
        var t_value = toConvert as bool?;
        if (t_value.HasValue)
          boolValue = t_value.Value;
      }
      //else
      //  boolValue = ConvertHelper.ToBool(toConvert);
 
      if ((parameter != null) && (parameter.ToString() == VisibilityHelper.INVERTER_PARAMETER))
        boolValue = !boolValue;
 
      return boolValue ? Visibility.Visible : Visibility.Collapsed;
    }
 
    public static bool VisibilityToBool(object toConvert, object parameter)
    {
      if ((parameter != null) && (parameter.ToString() == INVERTER_PARAMETER))
      {
        if (toConvert is Visibility)
          return (Visibility)toConvert != Visibility.Visible;
        else
          return false;
      }
      else
      {
        if (toConvert is Visibility)
          return (Visibility)toConvert == Visibility.Visible;
        else
          return false;
      }
    }
  }
 
  /// <summary>
  /// Permet les binding entre visibility et boolean
  /// </summary>
  public class BooleanToVisibilityConverter : IValueConverter
  {
 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      return VisibilityHelper.BoolToVisibility(value, parameter);
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      return VisibilityHelper.VisibilityToBool(value, parameter);
    }
  }
}


PS : Why i can't add attached zip file ... ?


A+
JC
0
Konstantina
Telerik team
answered on 27 Jul 2011, 08:20 AM
Hi Jc,

To attach a file, you will need to open a support ticket.
However, I was able to observe the issue using your code. The losing of the bindings is caused because the pane is initially made floating. That is how the Docking control is working - when the Pane is initially floating is not in the same visual tree as the other panes. As a work around I can suggest you to bind the toggle button and the TextBlock to the same view model property. In that way the binding won't be lost when the pane is floating, because it will be kept in the view model.
Please find attached a sample project illustrating this.

Hope this helps.

Best wishes,
Konstantina
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
JC
Top achievements
Rank 1
answered on 27 Jul 2011, 08:50 AM
No !!

Is not "by design" it's a BUG !!
This code works perfectly with the release 2011-Q1 and all version of 2010 release ... side effect of Q2 !!!

Please fix this bug now !
0
Miroslav Nedyalkov
Telerik team
answered on 01 Aug 2011, 05:00 PM
Hello Jc,

Thank you for reporting us this problem.

As Konstantina explained the binding gets broken because the pane is moved in a different visual tree. The same operation was performed before, but the root of the visual tree was the same so this problem didn't occur before Q2 2011. We needed to make some changes to improve the infrastructure of the Docking control which allowed us to add the Active pane feature.

We will investigate the cause of the problem in more details and if we are able to fix this problem we will do so. Yet I would suggest you to follow the Konstantina suggestion for working-around this problem.

All the best,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
JC
Top achievements
Rank 1
answered on 16 Aug 2011, 03:18 PM
Hello,

Thank to your reply, good luck to find the way :)
Can you tell me when the bug will be solved plz ?

And I've won any telerik point to this issue ?

Bye
0
Miroslav Nedyalkov
Telerik team
answered on 19 Aug 2011, 01:07 PM
Hello Jc,

 As this fix is not planned yet it will not be ready before the 2011 Q3 release. You can use PITS to track the progress of the issue.

Kind regards,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Bryce
Top achievements
Rank 1
answered on 14 Dec 2011, 11:06 PM
Hi,

I am running into the same issue. However, I cannot imitate what Konstantina has attached because what my pane is binding to is in another pane. I have a grid in one pane, and the other pane is bound to the row selected in the grid. When I grab the selected row pane and drag it around I lose the bindings. Is there a different way to fix this?

Thanks,
Bryce
0
Miroslav Nedyalkov
Telerik team
answered on 19 Dec 2011, 09:10 AM
Hello Bryce,

What I would suggest you is to bind both values to the same ViewModel. This way the value will be passed through the ViewModel and will not be lost.

Hope this helps.

Kind regards,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Bryce
Top achievements
Rank 1
answered on 20 Dec 2011, 07:37 PM
Hi Miroslav,

I believe I am already binding both values to the same view model. My RadGridView property is this:

SelectedItem="{Binding SelectedCase, Mode=TwoWay}"

public CaseViewModel SelectedCase { get;set;}

<View:CaseDetailedView DataContext="{Binding SelectedCase}"/>

Am I forgetting anything?

Thanks,
Bryce
0
Miroslav Nedyalkov
Telerik team
answered on 21 Dec 2011, 01:45 PM
Hi Bryce,

The SelectedCase property should throw property changed notifications and you should also notice that the floating ToolWindows don't inherit the DataContext of the RadDocking control and you need to bind their DataContext to the one of the RadDocking control.

If this doesn't help, could you please share a sample project that demonstrates the scenario with us. This way we will be able to better understand what the scenario is and help you to resolve the problem.

Greetings,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Bryce
Top achievements
Rank 1
answered on 22 Dec 2011, 08:39 PM
Hi Miroslav,

I am using MVVM and noticed that the examples given for ToolWindows is usually done in code-behind. Is there a way to set the DataContext of a tool window using MVVM, or would I have to set the DataContext in code-behind?

Thanks,
Bryce

[EDIT]
found this in another thread

private void radDocking_PaneStateChange(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            foreach (RadPane pane in radDocking.Panes)
            {
                if (pane != null && pane.IsFloating)
                {
                    ToolWindow toolWindow = GetToolWindow(pane);
                    toolWindow.Height = 200;
                    toolWindow.Width = 200;
                }
            }
        }
  
private ToolWindow GetToolWindow(RadPane pane)
        {
            ToolWindow window = pane.ParentOfType<ToolWindow>();
            if (window == null)
            {
                window = (((pane.Parent as RadPaneGroup).Parent as RadSplitContainer).Parent) as ToolWindow;
            }
            return window;
        }

And put:

toolWindow.DataContext = radDocking.DataContext

Bryce



0
Ivo
Telerik team
answered on 23 Dec 2011, 03:32 PM
Hi Bryce ,

You can create an implicit style into your app.xaml like this:
<Style TargetType="telerik:ToolWindow" >
    <Setter Property="DataContext" Value="{Binding Path=RadDockingViewModel, Source={StaticResource MainViewModel}}" />
</Style>

However, this has some disadvantages - for example all of your ToolWindows will have the same DataContext.

Hope this helps you.

Regards, Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Docking
Asked by
JC
Top achievements
Rank 1
Answers by
JC
Top achievements
Rank 1
Konstantina
Telerik team
Miroslav Nedyalkov
Telerik team
Bryce
Top achievements
Rank 1
Ivo
Telerik team
Share this question
or