RadTabControl: Value does not fall within expected range ... randomly

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    7 posts
    Member since:
    May 2011

    Posted 02 Nov 2011 Link to this post


    I have a RadTabControl that is loaded dynamically at runtime as the user adds tabs to it. The RadTabControl is sourced to an ObservableCollection<TabItemModel> where TabItemModel is defined below. As the user adds tabs to the control, I will randomly receive the error below. I am able to open sometimes 1, 2, or at maximum 3 tabs before receiving the error and having the app crash. I believe I was able to narrow the issue down to the Style of the TabItems, but I am stuck at an impass now. Any help would be greatly appreciated.

    Message: Unhandled Error in Silverlight Application
    Code: 4004    
    Category: ManagedRuntimeError       

    Message: System.ArgumentException: Value does not fall within the expected range.
       at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
       at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
       at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
       at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
       at System.Windows.Data.BindingExpression.SendDataToTarget()
       at System.Windows.Data.BindingExpression.SourceAcquired()
       at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
       at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
       at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)

    public class TabItemModel : INotifyPropertyChanged
            private FrameworkElement _content;
            public String Title { get; set; }
            public FrameworkElement TabContent
                    return _content;
                    _content = value;
            private void ClearParent(FrameworkElement _content)
                var contentPresenter = _content.Parent as ContentPresenter;
                if (contentPresenter != null)
                    contentPresenter.Content = null;
                var contentControl = _content.Parent as ContentControl;
                if (contentControl != null)
                    contentControl.Content = null;
            public bool IsSelected { get; set; }
            #region Interfaces
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            private void NotifyPropertyChanged(string name)
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(name));

    Add to tab event handler:
    void menuItemClick(object sender, RoutedEventArgs e)
        RadButton rb = sender as RadButton;
        TabItemModel tim = new TabItemModel();
            tim.Title = (rb.Content as VaultMenuItem).Title;
            Type type = Type.GetType(rb.Tag.ToString());
            tim.TabContent = Activator.CreateInstance(type) as UserControl;
        catch (Exception)
            tim.TabContent = new TextBlock() { Text = "An error has occurred in loading screen: " + rb.Tag.ToString() };
        tim.IsSelected = true;

    UserControl Resources:
            <telerik:ContainerBindingCollection x:Key="ClosableTabBindings">
                <telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay}" />
            <Style x:Key="ClosableStyle" TargetType="telerik:RadTabItem">
                <Setter Property="HeaderTemplate">
                        <DataTemplate telerik:ContainerBinding.ContainerBindings="{StaticResource ClosableTabBindings}">
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                <ContentControl Content="{Binding Title}"/>
                                <telerik:RadButton Grid.Column="1" Margin="3 0 0 0" Content="X" Width="18" Padding="0"
                                           Height="16" FontSize="10" HorizontalAlignment="Center" HorizontalContentAlignment="Center"
                                           VerticalAlignment="Center" VerticalContentAlignment="Center"
                                           local:RoutedEventHelper.EnableRoutedClick="True" />
                <Setter Property="ContentTemplate">
                            <ContentPresenter Content="{Binding TabContent}" />

    Thanks in advance,

  2. Petar Mladenov
    Petar Mladenov avatar
    2991 posts

    Posted 04 Nov 2011 Link to this post

    Hi Patrick,

     Could you please try setting the SupressSelectedContentTemplateReapplying to True and let us know if it helps you? You can find more info on how it works here. Thank you in advance for your cooperation.

    Petar Mladenov
    the Telerik team

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

  3. MEG.IR
    MEG.IR avatar
    8 posts
    Member since:
    Aug 2011

    Posted 18 Nov 2012 Link to this post

    Thank you so much for this.
    it works fine for me.
    Thank you again.
Back to Top