Databinding problem when using RadDocking without RadTabcontrol

2 posts, 0 answers
  1. Semih
    Semih avatar
    8 posts
    Member since:
    Aug 2014

    Posted 28 Aug 2014 Link to this post

    Hello,

    I am having a weird problem with the RadDocking control. You can find the example xaml code below. I am setting the datacontext of the UserControl from codebehind. And for the local:SelectedComponentsView control the DataContext binding is not being set!! But when I put the entire RadDocking object inside a Tabcontrol and TabItem, it works!!! But I don't want to use a TabControl to fix this problem. Please advice on the problem I am facing.

    Regards,

    <UserControl x:Class="MyProject.Engineering.Common.Controls.EnergyStateModelView"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"             xmlns:local="clr-namespace:MyProject.Engineering.Common.Controls"             xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"             mc:Ignorable="d"             d:DesignHeight="750" d:DesignWidth="1000">    <UserControl.Resources>        <SolidColorBrush x:Key="LightGrayBrush" Color="#FFEFEFF2" />        <SolidColorBrush x:Key="LightGrayBackgroundBrush" Color="#FFFFFFFF" />        <SolidColorBrush x:Key="DarkGrayBrush" Color="#FF424242" />        <SolidColorBrush x:Key="ContentForegroundBrush" Color="#FF020202" />        <SolidColorBrush x:Key="GreenBrush" Color="#FF388B41" />        <SolidColorBrush x:Key="DisableBrush" Color="#4C434647" />        <SolidColorBrush x:Key="LabelBrush" Color="#767676" />        <SolidColorBrush x:Key="ToolbarForegroundBrush" Color="#FF434647" />        <local:WidthConverter x:Key="WidthConverter"/>        <local:ItemToIndexConverter x:Key="IndexConverter"/>        <local:ResultToColorConverter x:Key="ColorConverter"/>        <local:InverseBooleanConverter x:Key="InverseBooleanConverter"/>        <controls:Windows8Colors x:Key="Windows8Colors" />        <SolidColorBrush x:Key="MarkerBrush" Color="{Binding Source={StaticResource Windows8Colors}, Path=Palette.MarkerColor}" />        <SolidColorBrush x:Key="AccentBrush" Color="{Binding Source={StaticResource Windows8Colors}, Path=Palette.AccentColor}" />        <SolidColorBrush x:Key="MainBrush" Color="{Binding Source={StaticResource Windows8Colors}, Path=Palette.MainColor}" />        <SolidColorBrush x:Key="BasicBrush" Color="{Binding Source={StaticResource Windows8Colors}, Path=Palette.BasicColor}" />    </UserControl.Resources>    <UserControl.InputBindings>        <KeyBinding Modifiers="Control" Key="N" Command="{Binding NewMenuCommand}"/>        <KeyBinding Modifiers="Control" Key="O" Command="{Binding OpenMenuCommand}"/>        <KeyBinding Modifiers="Control" Key="S" Command="{Binding SaveMenuCommand}"/>        <KeyBinding Modifiers="Control+Shift" Key="S" Command="{Binding SaveAsMenuCommand}"/>        <KeyBinding Modifiers="Control" Key="W" Command="{Binding CloseMenuCommand}"/>    </UserControl.InputBindings>    <Grid>        <Grid.RowDefinitions>            <RowDefinition Height="Auto"/>            <RowDefinition Height="*"/>        </Grid.RowDefinitions>        <StackPanel Grid.Row="0">            <telerik:RadMenu Name="mnuMain" Background="Transparent">                <telerik:RadMenuItem Header="FILE" >                    <telerik:RadMenuItem Name="NewItem" Header="_New"InputGestureText="Ctrl+N" Command="{Binding NewMenuCommand}"/>                    <telerik:RadMenuItem Name="OpenItem" Header="_Open"InputGestureText="Ctrl+O" Command="{Binding OpenMenuCommand}" CommandParameter="{Binding ElementName=EnergyStateModelView}"/>                    <telerik:RadMenuItem Name="OpenRecentItem" Header="Open Recent" ItemsSource="{Binding LastLogs}">                        <telerik:RadMenuItem.ItemTemplate>                            <DataTemplate>                                <StackPanel Orientation="Horizontal">                                    <MenuItem Header="{Binding FileName}" Command="{Binding Open}"/>                                </StackPanel>                            </DataTemplate>                        </telerik:RadMenuItem.ItemTemplate>                    </telerik:RadMenuItem>                    <telerik:RadMenuItem IsSeparator="True"/>                    <telerik:RadMenuItem Name="SaveItem" Header="_Save"InputGestureText="Ctrl+S" Command="{Binding SaveMenuCommand}"/>                    <telerik:RadMenuItem Name="SaveAsItem" Header="_Save As"InputGestureText="Ctrl+Shift+S" Command="{Binding SaveAsMenuCommand}"/>                    <telerik:RadMenuItem Name="CloseItem" Header="_Close"InputGestureText="Ctrl+W" Command="{Binding CloseMenuCommand}"/>                    <telerik:RadMenuItem IsSeparator="True"/>                    <telerik:RadMenuItem Name="ExitMenu" Header="_Exit"InputGestureText="Ctrl+Q" Command="{Binding ExitMenuCommand}"/>                </telerik:RadMenuItem>                <telerik:RadMenuItem Header="VIEW">                    <telerik:RadMenuItem Name="ComponentExplorerItem"Header="Component Explorer" IsCheckable="True" IsChecked="{Binding ElementName=tabFacility, Path=IsSelected, Mode=TwoWay}"/>                    <telerik:RadMenuItem Name="ConnectionExplorerItem"Header="Connection Explorer" IsCheckable="True" IsChecked="{Binding ElementName=tabConnection, Path=IsSelected, Mode=TwoWay}"/>                    <telerik:RadMenuItem IsSeparator="True"/>                    <telerik:RadMenuItem Name="MonitoringWindowDiagramItem"Header="Monitoring Window-Diagram"/>                    <telerik:RadMenuItemName="MonitoringWindowComponentTreeItem" Header="Monitoring Window-Component Tree"/>                    <telerik:RadMenuItem IsSeparator="True"/>                    <telerik:RadMenuItem Name="PropertiesWindow"Header="Properties Windows" IsCheckable="True" IsChecked="{Binding ElementName=PropertiesPane, Path=IsHidden, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}">                        <telerik:EventToCommandBehavior.EventBindings>                            <telerik:EventBinding Command="{Binding OnPropertiesWindowClickCommand}" CommandParameter="{Binding ElementName=PropertiesPane}" EventName="Click" />                        </telerik:EventToCommandBehavior.EventBindings>                    </telerik:RadMenuItem>                    <telerik:RadMenuItem IsSeparator="True"/>                    <telerik:RadMenuItem Name="OutputWindow" Header="Output Window" IsCheckable="True" IsChecked="{Binding ElementName=OutputPane, Path=IsHidden, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}">                        <telerik:EventToCommandBehavior.EventBindings>                            <telerik:EventBinding Command="{Binding OnOutputWindowClickCommand}" CommandParameter="{Binding ElementName=OutputPane}"EventName="Click" />                        </telerik:EventToCommandBehavior.EventBindings>                    </telerik:RadMenuItem>                </telerik:RadMenuItem>                <telerik:RadMenuItem Header="BUILD">                    <telerik:RadMenuItem Name="CompileMenuItem"Header="Compile" InputGestureText="Ctrl+B" Command="{Binding CompileCommand}"/>                    <telerik:RadMenuItem Name="DownloadMenuItem"Header="Download" InputGestureText="Ctrl+D" Command="{Binding DownloadMenuCommand}"/>                    <telerik:RadMenuItem IsSeparator="True"/>                    <telerik:RadMenuItem Name="SimulateMenuItem"Header="Simulate" InputGestureText="Ctrl+S"/>                </telerik:RadMenuItem>                <telerik:RadMenuItem Header="HELP" />            </telerik:RadMenu>        </StackPanel>         <!--Main Content Grid-->        <Grid Grid.Row="1">            <telerik:RadDocking x:Name="dockEngineering"                                             Grid.Row="1"Margin="0,0,0,0"                                                                              BorderThickness="0"                                            Padding="0" Background="{StaticResource LightGrayBrush}">                 <!--DocumentHost-->                <telerik:RadDocking.DocumentHost>                    <telerik:RadSplitContainer>                        <telerik:RadPaneGroup>                            <telerik:RadPane Header="Engineering">                                <local:SelectedComponentsViewDataContext="{Binding FacilityViewModel, Mode=TwoWay}"/>                            </telerik:RadPane>                            <telerik:RadPane Header="Monitoring">                                <Grid Name="grdMonitoring">                                </Grid>                            </telerik:RadPane>                            <telerik:RadPane Header="Forecast">                                <Grid Name="grdForecast">                                    <local:ForecastView DataContext="{Binding ForecastViewModel}"/>                                </Grid>                            </telerik:RadPane>                        </telerik:RadPaneGroup>                    </telerik:RadSplitContainer>                </telerik:RadDocking.DocumentHost>                 <telerik:RadSplitContainer  MaxWidth="600"telerik:DockingPanel.InitialSize="300,150"                            Name="LeftContainer"InitialPosition="DockedLeft">                    <telerik:RadPaneGroup x:Name="Group1">                        <telerik:RadPane x:Name="LeftPane" Header="Facility Explorer">                            <telerik:RadTabControl x:Name="tbcInner"x:FieldModifier="public" TabOrientation="Horizontal" TabStripPlacement="Bottom"SelectedIndex="0">                                <telerik:RadTabItem x:Name="tabFacility"x:FieldModifier="public" Header="Facility View" IsSelected="True">                                     <!--Server Exproler-->                                    <!--<telerik:RadPane x:Name="Pane11" Header="Facility Explorer">-->                                    <Grid Margin="3 0">                                        <local:FacilityViewx:Name="FacilityView" DataContext="{Binding FacilityViewModel, Mode=TwoWay}"/>                                    </Grid>                                    <!--</telerik:RadPane>-->                                 </telerik:RadTabItem>                                <telerik:RadTabItemx:Name="tabConnection" x:FieldModifier="public" Header="Connection View"IsSelected="False">                                     <!--<telerik:RadPane x:Name="Pane12" Header="Connection Explorer">-->                                    <Grid Margin="3 0">                                        <local:CommunicationViewx:Name="CommunicationView" DataContext="{Binding CommunicationViewModel}"/>                                    </Grid>                                    <!--</telerik:RadPane>-->                                 </telerik:RadTabItem>                            </telerik:RadTabControl>                        </telerik:RadPane>                    </telerik:RadPaneGroup>                </telerik:RadSplitContainer>                 <telerik:RadSplitContainer MaxWidth="679"telerik:DockingPanel.InitialSize="210,250" Width="400"                            x:Name="RightContainer"InitialPosition="DockedRight">                    <telerik:RadPaneGroup x:Name="Group2">                        <!--Properties-->                        <telerik:RadPane x:Name="PropertiesPane"Header="Properties">                            <Grid Margin="3 0">                                <Grid.RowDefinitions>                                    <RowDefinition Height="*" />                                </Grid.RowDefinitions>                                <local:PropertyEditorx:Name="PropertyEditor" Item="{Binding SelectedItem}"/>                            </Grid>                        </telerik:RadPane>                    </telerik:RadPaneGroup>                </telerik:RadSplitContainer>                 <telerik:RadSplitContainer                            x:Name="BottomContainer"InitialPosition="DockedBottom">                    <telerik:RadPaneGroup x:Name="Group3">                        <!--Properties-->                        <telerik:RadPane x:Name="OutputPane" Header="Output Window">                            <Grid Margin="3 0">                                <Grid.RowDefinitions>                                    <RowDefinition Height="*" />                                </Grid.RowDefinitions>                                <ListView Name="OutputBox"VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="LightYellow"ItemsSource="{Binding OutputMessages}">                                    <telerik:EventToCommandBehavior.EventBindings>                                        <telerik:EventBindingCommand="{Binding OnOutputBoxSelectedCommand}" CommandParameter="{Binding ElementName=OutputBox, Path=SelectedItem}" EventName="SelectionChanged" />                                    </telerik:EventToCommandBehavior.EventBindings>                                    <ListView.ItemContainerStyle>                                        <StyleTargetType="ListViewItem">                                            <SetterProperty="Background" Value="{Binding ResultType, Converter={StaticResource ColorConverter}}"/>                                        </Style>                                    </ListView.ItemContainerStyle>                                    <ListView.View>                                        <GridView>                                            <GridViewColumnHeader="Number" DisplayMemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource IndexConverter}}"/>                                            <GridViewColumnHeader="Description" DisplayMemberBinding="{Binding MessageContent}" Width="{Binding ElementName=OutputBox, Path=ActualWidth, Converter={StaticResource WidthConverter},ConverterParameter=1}"/>                                        </GridView>                                    </ListView.View>                                </ListView>                            </Grid>                        </telerik:RadPane>                    </telerik:RadPaneGroup>                </telerik:RadSplitContainer>            </telerik:RadDocking>        </Grid>    </Grid> </UserControl>
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 28 Aug 2014 Link to this post

    Hi Semih,

    As we see that you have posted a support thread with ID: 854287 about the same issue could we continue the discussion there. I will post our response from that thread in this thread also in order for it to be available to the community:

    We are not aware of issues that could lead to this unexpected behavior when the DataContext is passed to the RadPane instances. We tried to reproduce the described issue but to no avail. When the DataContext of the UserControl in which the RadDockig is placed is set via the code behind and/or as a StaticResource the corresponding binding to the custom UserControls (ForecastView etc.) is correctly resolved. Note that when working with RadDocking and statically declared RadPane instances which rely on a DataContext, it is recommended to explicitly set the DataContext of those RadPane instances rather than leaving that context to be inherited by the structure. This is because the RadDocking control has features that remove the RadPane instances from the visual tree (making a pane floating) which could cause the DataContext to be lost in the process.

    Regards,
    Vladi
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top