This question is locked. New answers and comments are not allowed.
Hello-
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)
TabItemModel:
Add to tab event handler:
UserControl Resources:
Thanks in advance,
Patrick
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)
TabItemModel:
public class TabItemModel : INotifyPropertyChanged { private FrameworkElement _content; public String Title { get; set; } public FrameworkElement TabContent { get { this.ClearParent(_content); return _content; } set { _content = value; NotifyPropertyChanged("Content"); } } 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)); } } #endregion #endregion }Add to tab event handler:
void menuItemClick(object sender, RoutedEventArgs e){ RadButton rb = sender as RadButton; TabItemModel tim = new TabItemModel(); try { 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; this.Tabs.Add(tim);}UserControl Resources:
<UserControl.Resources> <telerik:ContainerBindingCollection x:Key="ClosableTabBindings"> <telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay}" /> </telerik:ContainerBindingCollection> <Style x:Key="ClosableStyle" TargetType="telerik:RadTabItem"> <Setter Property="HeaderTemplate"> <Setter.Value> <DataTemplate telerik:ContainerBinding.ContainerBindings="{StaticResource ClosableTabBindings}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <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" /> </Grid> </DataTemplate> </Setter.Value> </Setter> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <ContentPresenter Content="{Binding TabContent}" /> </DataTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources>Thanks in advance,
Patrick