Content re-loaded during each state transition

3 posts, 0 answers
  1. dxk240
    dxk240 avatar
    9 posts
    Member since:
    Feb 2011

    Posted 09 Nov 2011 Link to this post

    When using the RadFluidContentControl to manage state transitions inside of a TileView, I just noticed that the actual content is reloaded (meaning that the UserControl Loaded event is fired) every time the state is changed. This has a negative impact on performance because the UserControl will trigger binding every time the state changes. Especially in cases where the UserControl has a lot of data bound to it. Could you offer any guidance on how this could be avoided? I understand that RadFluidContentControl inherits from the ContentControl which has the same behavior (which in many cases is desired since one is explicitly changing the content of the control). However, in case of a TileView, the already loaded content is not changing all the time, it should just be switching between the different states (large, small, restored).

    Any help would be appreciated.
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 14 Nov 2011 Link to this post

    Hello Dxk240,
    As you've noticed the RadFluidContentControl uses a ContentControl (it actually uses a RadTransitionControl, but it inherits from a ContentControl) and it just changes it's content with some animation. Unfortunately there's no easy way to workaround the default behavior of the ContentControl (the reloading of the usercontrols). You can try to move most of the logic of your usercontrols inside the constructor so that it won't be executed on every reload or you can try simulate an RadFluidContentControl with something like this:
    XAML:
    <telerik:RadTileView x:Name="myTileView"
                          MinimizedColumnWidth="250"
                          TileStateChanged="RadTileView_TileStateChanged">
        <telerik:RadTileView.ContentTemplate>
            <DataTemplate>
                <Grid>
                    <local:FirstUserControl Visibility="Collapsed" />
                    <local:SecondUserControl />
                    <local:ThirdUserControl Visibility="Collapsed" />
                </Grid>
            </DataTemplate>
        </telerik:RadTileView.ContentTemplate>
    </telerik:RadTileView>
    C#:
    private void RadTileView_TileStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        var container = e.OriginalSource as RadTileViewItem;
        if (container != null)
        {
            var firstControl = container.ChildrenOfType<FirstUserControl>().FirstOrDefault();
            var secondControl = container.ChildrenOfType<SecondUserControl>().FirstOrDefault();
            var thirdControl = container.ChildrenOfType<ThirdUserControl>().FirstOrDefault();
     
            switch (container.TileState)
            {
                case TileViewItemState.Restored:
                    firstControl.Visibility = System.Windows.Visibility.Collapsed;
                    secondControl.Visibility = System.Windows.Visibility.Visible;
                    thirdControl.Visibility = System.Windows.Visibility.Collapsed;
                    break;
                case TileViewItemState.Maximized:
                    firstControl.Visibility = System.Windows.Visibility.Collapsed;
                    secondControl.Visibility = System.Windows.Visibility.Collapsed;
                    thirdControl.Visibility = System.Windows.Visibility.Visible;
                    break;
                case TileViewItemState.Minimized:
                    firstControl.Visibility = System.Windows.Visibility.Visible;
                    secondControl.Visibility = System.Windows.Visibility.Collapsed;
                    thirdControl.Visibility = System.Windows.Visibility.Collapsed;
                    break;
                default:
                    break;
            }
        }
    }
    but you'll lose the animations.
    If you have more questions please feel free to ask.

    Regards,
    Zarko
    the Telerik team

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

  3. DevCraft banner
  4. dxk240
    dxk240 avatar
    9 posts
    Member since:
    Feb 2011

    Posted 15 Nov 2011 Link to this post

    Zarko,
        Thank you for your reply. I was afraid what your workaround will consist of. Thank you anyways.
Back to Top