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

RadPane IsPinned="False" Model View Binding

2 Answers 258 Views
Docking
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 1
David asked on 09 Oct 2012, 02:25 PM
Hi,

I've run into a problem binding controls to code-behind object properties on any RadPane that has the IsPinned property set to false.

Quick test program below; three RadPanes each with a TextBox, each bound to the Name property of a Person object. Pane 1 and 3 are pinned and correctly show the Name, Pane 2 has IsPinned set to false, and doesn't show the property when it's pinned into view.

Any ideas?

TIA.
<controls:ChildWindow x:Class="Test.Silverlight.Views.RadPaneTest"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
           Width="400" Height="300"
           Title="RadPaneTest">
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadDocking HasDocumentHost="False" HorizontalAlignment="Stretch" Margin="2" Name="rdHeader" VerticalAlignment="Stretch">
            <telerik:RadSplitContainer InitialPosition="DockedTop">
                <telerik:RadPaneGroup Name="rpgSupplier" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <telerik:RadPane Header="Pane 1" telerik:RadDocking.SerializationTag="Pane1">
                        <TextBox Text="{Binding Path=Person.Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:ChildWindow}}" />
                    </telerik:RadPane>
                    <telerik:RadPane IsPinned="False" Header="Pane 2" telerik:RadDocking.SerializationTag="Pane2">
                        <TextBox Text="{Binding Path=Person.Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:ChildWindow}}" />
                    </telerik:RadPane>
                    <telerik:RadPane Header="Pane 3" telerik:RadDocking.SerializationTag="Pane3">
                        <TextBox Text="{Binding Path=Person.Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:ChildWindow}}" />
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking>
         
        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
        <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
    </Grid>
</controls:ChildWindow>


using System.Windows;
using System.Windows.Controls;
 
namespace Test.Silverlight.Views
{
    public partial class RadPaneTest : ChildWindow
    {
        private Person m_Person;
 
        public RadPaneTest()
        {
            InitializeComponent();
 
            m_Person = new Person();
        }
 
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
 
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
 
        public Person Person
        {
            get { return m_Person; }
        }
    }
 
    public class Person
    {
        public Person()
        {
            Name = "Bob";
        }
 
        public string Name { get; set; }
    }
}
asdasd

2 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 11 Oct 2012, 11:14 AM
I'm either doing something so dumb noone can be bothered to point out the obvious, or something that cannot be fixed and noone knows the answer.

I can't believe noone has had this problem.

You set up docking panes, but, by default, you want one or more panes to be unpinned at startup. The bindings don't work when the pane is pinned into view if the binding is to a RelativeSource object, i.e. the code-behind page.

I've seen something similar with ContextMenu, and have worked around it by creating a custom PageContext object in the XAML Resources which has a "Page" property set in the MyPageType_Loaded event;
 
(this.Resources["PageContext"] as MyPageType).Page = this;

and changing the binding from RelativeSource={Mode=FindAncestor, AncestorType=controls:ChildWindow} to Source={StaticResource PageContext}.

This works but it's very hacky.

Is there a better way?
0
Accepted
Vladi
Telerik team
answered on 15 Oct 2012, 07:24 AM
Hello David,

In RadDocking when a Pane is unpinned it is taken out of the visual tree that is why when binding a control that is in a Pane to a RelativeSource the binding gets broken.

As you said you could fix the issue by binding to a StaticResource which is not a hack in any way or you could bind the RadDocking DataContext to the ChildWindow and then bind the TextBox to the DataContext of the RadDocking. That way the binding will not get broken when you pin/unpin a Pane.

Hope this helps.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Docking
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Vladi
Telerik team
Share this question
or