Cause all items UIElements to load

4 posts, 0 answers
  1. Nick Wood
    Nick Wood avatar
    126 posts
    Member since:
    Feb 2010

    Posted 17 Jun 2010 Link to this post

    Hi All

    I have bound the ItemSource of the RadBook to an ObservableCollection of classes, then I am using the item template to create a user control that binds it DataContext to the object. This is working well. I found however that I need to ensure that all the UserControls are loaded as soon as the ItemSource of the RadBook is Updated. Right now they only load when you navigate to that page.

    Is there any method that I can call that does not require me to cause the book to iterate through all the pages?

    Thanks for you help

    Nick
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Jun 2010 Link to this post

    Hi Nick,

     If you do this you may get highly unresponsive application. How many pages you have?

    Kind regards,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nick Wood
    Nick Wood avatar
    126 posts
    Member since:
    Feb 2010

    Posted 17 Jun 2010 Link to this post

    Hi Vlad

    There is never usually any more that 10 items (on average there would only be about 5).

    So is there any way to ensure all elements/pages are loaded without iterating the items?

    Thanks

    Nick
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 21 Jun 2010 Link to this post

    Hi Nick,

    With our Beta release (0609) we added a new property to RadBook called IsVirtualizing. This property turns off RadBook's UI virtualization (i.e reuse old book item containers). Let me explain how the IsVirtualizing property works in order for you to determine whether it is going to help.
    Imagine the following scenario. You have a UserControl that contains just a single TextBlock whose Text property is bound to the Title property of your business object:

    <UserControl x:Class="WpfApplication3.UserControl1"
        <Grid>
            <TextBlock Text="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Center"
                    FontSize="36" />
        </Grid>
    </UserControl>

    In the DataTemplate of RadBook, you use this user control:

    <Window x:Class="WpfApplication3.Window1"
            xmlns:local="clr-namespace:WpfApplication3"
            xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
            xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
            Title="Window1">
        <Window.Resources>
            <DataTemplate x:Key="PageTemplate">
                <Border BorderThickness="1" BorderBrush="Black" Background="LightGoldenrodYellow">
                    <local:UserControl1 />
                </Border>
            </DataTemplate>
        </Window.Resources>
        <Grid>
            <telerikNavigation:RadBook x:Name="book1" Width="500" Height="500"
                    LeftPageTemplate="{StaticResource PageTemplate}"
                    RightPageTemplate="{StaticResource PageTemplate}" IsVirtualizing="False"/>
        </Grid>
    </Window>
     
    Finally you populate RadBook with a collection of 10 items:

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
             
            // Create a collection of 10 items that will server as RadBook's ItemsSource
            book1.ItemsSource = Enumerable.Range(0, 10).
                            Select(i => new DataItem()
                            {
                                Title = string.Format("Item {0}", i)
                            });
        }
    }
     
    public class DataItem
    {
        public string Title { get; set; }
    }

    Now, if you attach to the loaded event of UserControl1...

    public UserControl1()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(UserControl1_Loaded);
    }
     
    void UserControl1_Loaded(object sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Loaded"); 
    }

    ...and run the application, you will see the Loaded message displayed 2 times. Turn to the next page and the message will be displayed 2 more times. When you reach the last page, the Loaded message should be displayed 10 times (the total number of items in the collection).
    Now, if you start going back to the first page, the Loaded message will not be displayed any more, since IsVirtualizing has been set to False and all the containers have been generated. If IsVirtualizing was set to True then once you start going back to the first page, the Loaded message will get displayed.

    Currently there is no way to generate all the containers once the ItemsSource is set. You have to turn all the pages at least once for all the containers to get generated.
    Play around with the IsVirtualizing property and let me know if it will do the job. Let me know how I can be of further assistance.

    On a side note, I'd like to inform you that we've just released an online tool that allows you to reduce the size of your Silverilght applications. For more information, please visit http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx

    Kind regards,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top