Crashed when click previous button

2 posts, 0 answers
  1. Yue
    Yue avatar
    16 posts
    Member since:
    Aug 2011

    Posted 01 Nov 2011 Link to this post

    Hi All,

    I used RadDataPager + RadTileView in my Silverlight.
    And the data loading part works well.

    But, when I change page by clicking at previous or first buttons, my silverlight page always get a crash  :
    Error:Value does not fall within the expected range.

    Here is my code:
    BusinessItemViewModel.cs
    public class BusinessItemViewModel
    {
    public string Header { get; set; }
    public TextBlock TB { get; set; }
    public BusinessItemViewModel(int i)
    {
    this.Header = i.ToString();
    this.TB = new TextBlock();
    this.TB.Text = "HyperlinkButton" + i.ToString() ;
    }
    }



    <UserControl.Resources>       
        <Style TargetType="telerik:RadTileView">
            <Setter Property="ColumnWidth" Value="325" />
            <Setter Property="RowHeight" Value="275" />
            <Setter Property="MinimizedColumnWidth" Value="180" />
            <Setter Property="MinimizedRowHeight" Value="155" />
            <Setter Property="ColumnsCount" Value="10" />
            <Setter Property="IsVirtualizing" Value="True" />
            <Setter Property="PreservePositionWhenMaximized" Value="True" />
        </Style>
        <Style TargetType="telerik:RadTileViewItem">
            <Setter Property="Background" Value="#06749b" />
        </Style>
        <DataTemplate x:Key="headerTemplate">
            <TextBlock Text="{Binding Header}" />
        </DataTemplate>  
        <DataTemplate x:Key="contentTemplate">
            <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"></RowDefinition>
                <RowDefinition Height="auto"></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           FontSize="48"
                           FontStyle="Italic"
                           Foreground="#FFFF00"
                           Text="{Binding Header}" />
            <HyperlinkButton Content="{Binding TB}" FontSize="30" Grid.Row="1"/>
        </Grid>
        </DataTemplate>
    </UserControl.Resources>
     
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>       
        <telerik:RadTileView x:Name="myTileView"
                             ContentTemplate="{StaticResource contentTemplate}"
             ItemsSource="{Binding PagedSource, ElementName=myDataPager}"
             ItemTemplate="{StaticResource headerTemplate}" />
        <telerik:RadDataPager x:Name="myDataPager"
             Grid.Row="1"
             PageSize="100"/>
        <Button Click="LoadData" Content="Click Here to Load Data" FontSize="15" Grid.Row="2"></Button>       
        </Grid>
    </UserControl>

    private ObservableCollection<BusinessItemViewModel> items = new ObservableCollection<BusinessItemViewModel>();
         
    public MainPage()
    {
        InitializeComponent();
            this.LoadSomeItems();          
    }
    public ObservableCollection<BusinessItemViewModel> Items
    {
        get
        {
            return this.items;
        }
    }
    private void LoadSomeItems()
    {  
        for (int i = 0; i < 10000; i++)
        {
            this.items.Add(new BusinessItemViewModel(i));
        }         
    }
    private void LoadData(object sender, RoutedEventArgs e)
    {
        myDataPager.Source = items;
    }

    When I delete the property: public TextBlock TB { get; set; } in my BusinessItemViewModel class,
    this DataPager  works fine.

    So, is this  the TextBlock  Control the reason of this crash?
    How can I fix this thing?

    I tried this:Zarko's blog, and modified to the code I listed above.

    Thanks

  2. Yue
    Yue avatar
    16 posts
    Member since:
    Aug 2011

    Posted 02 Nov 2011 Link to this post

    I have found the reason.

    The same TextBlock control can not be added twice.   ( - -!)
  3. DevCraft banner
Back to Top