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

Changing the DataContext of a Pane is not working

3 Answers 140 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 15 Aug 2013, 02:11 PM
Hello,
create a new SIlverlight 5 application, add references to Telerik.Windows.Controls, Telerik.Windows.Controls.Docking and Telerik.Windows.Controls.Navigation.

Then replace MainPahe.xaml with:
<UserControl
  x:Class="SilverlightApplication1.MainPage"
  mc:Ignorable="d"
  d:DesignHeight="300" d:DesignWidth="400">
 
  <tk:RadDocking>
    <tk:RadSplitContainer>
      <tk:RadPaneGroup>
        <tk:RadPane Name="Pane"
                    Header="Pane">
          <StackPanel Margin="5">
             
            <TextBlock HorizontalAlignment="Left"
                       Margin="2"
                       Text="{Binding}" />
 
            <tk:RadButton Content="Context to 123"
                          HorizontalAlignment="Left"
                          Margin="2"
                          Click="RadButton_Click" />
 
            <tk:RadButton Content="Context to ABC"
                          HorizontalAlignment="Left"
                          Margin="2"
                          Click="RadButton_Click_1" />
 
          </StackPanel>
        </tk:RadPane>
      </tk:RadPaneGroup>
    </tk:RadSplitContainer>
  </tk:RadDocking>
</UserControl>

and replace MainPage.xaml.cs with:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
 
namespace SilverlightApplication1
{
  public partial class MainPage : UserControl
  {
    public MainPage()
    {
      InitializeComponent();
      Pane.DataContext = "None";
    }
 
    private void RadButton_Click(object sender, RoutedEventArgs e)
    {
      Pane.DataContext = "123";
    }
 
    private void RadButton_Click_1(object sender, RoutedEventArgs e)
    {
      Pane.DataContext = "ABC";
    }
  }
}

Now run the application.
The DataContext that is set at the beginning is working, but the change of the DataContext is not propagated to the children controls.
If I set the DataContext of the main page or of the StackPanel, it works correctly!

Patrick

3 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 20 Aug 2013, 07:57 AM
Hi Patrick,

When you change the DataContext, it is not used on the children of the RadPane by design. In order to get it working, you will have to change the DataContext of RadPane's Content (as you have noticed, if you set the DataContext of the StackPanel, it works fine). Changing the DataContext of RadPane is only applied on the Header area of the Pane.

Hopefully this helps. Feel free to contact us in case you have any problems or concerns. 

Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 20 Aug 2013, 08:03 AM
Rosen,
that's not totally true: when I set the DataContext on the RadPane the first time, it is working. So this is confusing: why does it work the first time and not the second one?
Also, if this is by design, this should be documented. Because the Silverlight way of doing things is that children elements inherit the DataContext of their parent.
Patrick
0
Rosen Vladimirov
Telerik team
answered on 20 Aug 2013, 02:31 PM
Hi Patrick,

When you set the DataContext immediately after InitializeComponent() or in XAML, the Content of RadPane is still inside it, as this is the way it is defined in XAML. But internally we are applying some changes, so if you use a timer and set the DataContext on RadPane after the internal operation has finished, the TextBlock will not receive this DataContext. That's why we recommend you to set the DataContext on the Content itself.

Hopefully this helps. Feel free to contact us in case you have any problems or concerns. 

Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Docking
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Rosen Vladimirov
Telerik team
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or