Tab reloads control after switching tab

35 posts, 0 answers
  1. David
    David avatar
    21 posts
    Member since:
    Apr 2009

    Posted 11 May 2009 Link to this post

    Hi,

    this might be what it's mean't to do but when i switch tabs once the controls have been loaded they seem to reload when i switch back to a previous selected tab? is this correct?

    forgot to say that it's using ItemContainerStyleSelector for each tab is databound to a collection.

    David
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 11 May 2009 Link to this post

    Hello David,

    Yes - this is expected behavior, since when the content of the tab item is detached from the visual tree once it should not be visible and then attached to the visual tree when the item content should get visible again.

    Regards,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 13 Jul 2009 Link to this post

    Hi,

    is there any workaround for this issue? In our application, in one of the tabs we are connecting our legacy client using browser plug-in and when I switch back to this tab it is reloading the plug-in and terminating the previously started connection. This is also true if we have a Grid in the tab and everytime we switch it reloads the grid again by running the WCF service call etc.

    I read somewhere that in native (silverlight) tab control it retains the current state of each tab and does not reload the contents. Is it true? If it is true then why telerik tab control behaves differently?

    this is a major concern for our application and this really depends what controls to use for our application.

    Please advice as soon as possible.

    Thank you very much for your help.

    Srinivas
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 14 Jul 2009 Link to this post

    Hi Srinivas,

    I created an example where you can see that the Loaded event is called in the standard TabControl just like it is in the RadTabControl. There is a solution for your problem though and I have also included it in the project.

    The TabControl removes the content when no longer needed because the content of the TabItem could be anything, including something "heavy".

    If this is not the case for you, you can use the TabControl as a Tabstrip control (just for showing buttons) and then show the selected item. Please note though that then the content of all your tab items will be loaded.

    Does this work for you?

    Best wishes,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 14 Jul 2009 Link to this post

    Hello Miroslav,

    Thank you very much for your quick response.

    Unfortunately, the solution that you provided may not work for us as our application is very large in size (it is an ERP system with 50+ modules) and the contents of each tab are separate transactions and loaded dynamically (xap files). Also, some transaction pages will contain both Silverlight/Telerik controls like RadGridView and some other UI elements plus a plug-in to our legacy client at the bottom of the page. When the user selects a record of RadGridView then we load our client at the bottom of the page to load the full transaction with the user selection. 

    We are taking this approach for many transactions as we will be moving in phases to Silverlight/Telerik and then eventually replacing our legacy client.

    Is there any alternate solution to solve this issue? The RadTabControl is very critical for our UI framework as we like to allow our users to run more than one transaction at the same time by providing multiple tabs. 

    Please advice.

    Thanks
    Srinivas
  7. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 14 Jul 2009 Link to this post

    Hi Srinivas,

    As I understand, you would not like to load all the Tabs at once, which of course should not happen.

    The you say: "...as we like to allow our users to run more than one transaction at the same time by providing multiple tabs".  Could you confirm that this is what you need:

    1. Only the tabs that the user selects should be loaded
    2. No tabs should be unloaded (so they will not be reloaded when the user switches to them)
    3. Yet, only the currently selected tab should be visible to the user (i.e. you are not expecting the user to see more than one selected tab in the same tab control)

    Also, could you share what triggers the transactions.
    4. Are you dependent on the Loaded events or on other events that fire again (unexpectedly in your case) when you switch back to the tab.

    I am thinking that some kind of caching or flags could prevent the transactions from starting again.

    Best wishes,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 14 Jul 2009 Link to this post

    Hello Miroslav,

    A transaction is like maintaining a "Product Details" (using productdetails.XAML file) and when the user select an option from the RadTreeViewItem then I would like to create a new RadTabItem (dynamically) and load the "Product Details" XAML page in that new tab. After loading the XAML into the new tab the user may want to lookup something else and may select another option from the RadTreeViewItem and when the second selection happens I want to create a new RadTabItem and load the second XAML page in the second tab. But if the user selects "Product Details" option again then I would like to switch to the first tab as the page already loaded once.

    Please find below my answers:

    1A: Yes and as I explained above, the tabs are created dynamically (maximum 5 only to save memory) when the user selects option from the Menu tree

    2A: Yes, we do not want to unload already loaded tabs so that while adding "Product Details" the user can switch to another tab to verify "Product Pricing" details and come back to "Product Details" tab and continue transaction.

    3A: Yes, at any given point of time the user is allowed to view or work with only one tab and not more than one.

    4A: Mostly Loaded events, the only trigger point to create a tab or load a XAML file is when the user selects an option from the menu tree and possibly in some cases where the user click on a "View Pricing" button of one XAML file and in that case we want to create a new tab and load "Pricing Details" in the new tab.

    I thought of exploring options to create flags and control the reload process but I am not sure if the entire XAML file is reloaded or only the methods (code behind) are reexecuted. Also, if you can advice me on the flags, like where to create them and update them etc that would be great.

    Thanks
    Srinivas

  9. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 15 Jul 2009 Link to this post

    Hello Srinivas,

    Thank you for the clarifications!

    Here are my thoughts on this, I am not sure whether they all apply to your case. 

    The Loaded event is fired when a visual item is added to the Visual Tree. Unfortunately there is no Unloaded event, it is needed sometimes. IMO the Loaded handler should contain only things for UI initialization like focusing a convenient item, and (re)setting properties that are not bound.

    In Silverlight there is ISupportInitializae interface (similar to WPF) but for some obscure reason it is internal and used only by some MS controls. It could have helped here.

    The place to do one-time initialization could be the constructor for the UserControl and OnApplyTemplate for the custom control (if you have any).

    When things are added/removed from the visual tree a big performance hit comes from updating inherited properties, mostly the DataContext. If possible make sure that the pages that are added/removed have a DataContext explicitly set to them. Even if the datacontext is set to the DataContext they would normally inherit. This means that all the controls inside will not rebind on tab switch, which can be expensive, especially for ItemsControls.

    To answer your question: When something is added to the Visual tree only the loaded event is called, i.e. no constructors are called or visuals are recreated.

    So in short: move one-time initialization of the pages to constructor/OnAppyTemplate or add an isLoaded flag to the controls and make sure that expensive calls happen just once. Also be careful with the DataContext reloading.

    I am sorry that I cannot provide more specific advice, but I would have to guess how things work on your side.

    Hopefully you will be able to flag/move the expensive initialization.

    Best wishes,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 15 Jul 2009 Link to this post

    Hello Miroslav

    Thank you very much for the details. If you don't mind can you please elaborate below paragraph from your previous post?
    -------------
    When things are added/removed from the visual tree a big performance hit comes from updating inherited properties, mostly the DataContext. If possible make sure that the pages that are added/removed have a DataContext explicitly set to them. Even if the datacontext is set to the DataContext they would normally inherit. This means that all the controls inside will not rebind on tab switch, which can be expensive, especially for ItemsControls
    -------------

    I really appreciate all your help and support.

    Thank you very much
    Srinivas
  11. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 16 Jul 2009 Link to this post

    Hello Srinivas,

    The discussion is worthy of a blog post, if I have the time I will try to put one together :)

    Lets start from further away, you may know most of these things but I still would like to explain them, hopefully they will be useful to the devs that read the forum :).

    The DataContext property is inherited through the visual tree. You can set an object as data context to the root panel in your application and it will be inherited throughout your application, every rectangle, every little visual object in all the controls and parts of your application will inherit this data context.

    This means that if you replace the DataContext, the whole application will rebind and the whole visual tree has to be walked, the effective DataContext value has to change for every object and this is expensive. You can imagine that you have bound the ItemsSource of a control with, say 1000 items. Since the data context has changed, the binding is reevaluated then the ItemsSource has potentially changed and you have to recreate the items of the ItemsControls. I.e. changing the DataContext property can be expensive.

    Now, I simplified the inheritance of the DataContext property. Actually in ItemsControls the DataContext of the container control is NOT the one of its parent. The DataContext of the container is the item itself.

    Then there is another case where the DataContext is not directly inherited, the ContentControl.
    When you have a content control the visuals in the ContentTemplate are placed as visual children in the content presenter of the content control. Then the Content of the ContentControl is set as a DataContext of these visuals, so that you can have bindings in the ContentTemplate that bind to the Content.
    BUT! If you do not use a ContentTemplate and you just set a visual as content, this visual will inherit the DataContext of the ContentControl.

    Now we are getting close to your specific case.
    1. Whenever you add something to the visual tree if it does not have a DataContext it will inherit the data context of its parent visual. So you are not just adding something, you are adding something and invalidating the DataContext property of some (up to most) of the visuals you add.

    2. I understand that you are binding the control and adding UserControl loaded from somewhere else in the ContentTemplate of the TabItem or as its Content. Each time you add this page to the Visual tree it will inherit the current one DataContext. Then when you remove it, it will reset its DataContext. I was worried that you may be experiencing slowdowns because of the reloading.

    3. What you can do here is set explicit DataContext to the pages you reload (even if it is the one they would normally inherit). This way when you can cache them without worrying that adding/removing them to the visual tree will be expensive because of the DataContext reset. Of course it depends on how much you bind in these pages. If you do not bind them or you set explicit context you should not experience slowdowns because of this.

    So in short: Instead of loading your pages anew, load them just once and cache them. Then do not load them again but show the loaded page, just make sure that resetting the DataContext is not too expensive or set explicit DataContext.

    Again, since do not know the specifics of your application I could only guess how it could be optimized.

    There are many things to be considered for improving app performance and I am not sure whether this helps you but such things are good to know.

    I created a simple example illustrating context inheritance, it is attached.

    I would be interested to know whether you managed to improve the performance in your app with some caching or otherwise.

    Kind regards,

    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  12. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 16 Jul 2009 Link to this post

    Hello Miroslav,

    Thank you so much for your explanation and from this I learned a lot. Thanks once again.

    Below is the code from the main xaml page (framework page). I have placed some comments in the code to explain what it is, if you need any further clarifications please let me know. After reading the code probably you can answer below questions.

    1. Is it the right way of caching the loaded tab items?
    2. When I remove the tab item from the tab group in RemoveTabItem method does Garbage Collection will clean it up?
    3. Is it advisable to place App.RefreshUserProfileTab flag in the App.xaml.cs?
    4. Any further advice on this would be of great help.

    Thank you so much for your advice and help.
    Srinivas

    PageModule will contain the XAP file name (to load dynamically) and the PageName contains the page inside that XAP. if PageModule is empty then it loads from the same XAP file
    XAML tree item definition
    =========================
    <GTree:GTreeViewItem Header="Open Orders" Name="OpenOrders" 
                                                              Selected="RadTreeViewItem_Selected"
                                                              TabTitleName="Open Orders"
                                                              PageModule="SOModule"
                                                              PageName="SalesOrdersPage"/>
    =========================
    Code-behind
    =========================
    public partial class Page : UserControl
        {
            public RadTabControl tabgroup;
    //dictionary to cache already loaded tabitems
            private Dictionary<String, RadTabItem> loadedtabs;
    //GTreeViewItem is defined as GTreeViewItem : RadTreeViewItem with additional properties
            GTreeViewItem selectedTreeItem;
            RadTabItem tabitem;
            String ModuleDLL;
            String ModulePageName;
            public Page()
            {
                InitializeComponent();
                loadedtabs = new Dictionary<string, RadTabItem>();
                Loaded += new RoutedEventHandler(Page_Loaded);
            }

            void Page_Loaded(object sender, RoutedEventArgs e)
            {
    //as an experiment, i have added a flag in App.xaml.cs to indicate whether to refresh or not
    //initially set the refresh to true
                App.RefreshUserProfileTab = true;
    //load the user profile page as default page
                homeTabItem.Content = new GApp.Contents.UserProfilePage();
    //save the user profile tab item in the dictionary...is it what caching????
                loadedtabs[homeTabItem.Name] = homeTabItem;
            }

            private void RadTreeViewItem_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                selectedTreeItem = (GTreeViewItem)sender;
                selectedTreeItem.IsSelected = false;
    //if the tabitem is already created and exists in the dictionary then load the same tabitem
                if (loadedtabs.ContainsKey(selectedTreeItem.Name))
                {
                    AppTabGroup.SelectedItem = loadedtabs[selectedTreeItem.Name];
                }
                else
                {
    //if the tabitem not created previously then create new tabitem
                    if (AppTabGroup.Items.Count == App.MaxAllowedTabs)
                    {
                        MessageBox.Show("Maximum 5 tabs are allowed");
                        return;
                    }
                    tabitem = new RadTabItem();
                    tabitem.Header = selectedTreeItem.TabTitleName;
                    tabitem.MinWidth = 125;
                    tabitem.Name = selectedTreeItem.Name;
                    //if the page exists within the same xap file then create an instance of that page 
    //otherwise load corresponding xap file dynamically (in else section)
                    if (selectedTreeItem.PageModule == "")
                    {
                        var pageInstance = Assembly.GetExecutingAssembly().CreateInstance(selectedTreeItem.PageName);
                        tabitem.Content = pageInstance;
                        AppTabGroup.Items.Add(tabitem);
                        AppTabGroup.SelectedItem = tabitem;
    //add new tabitem to dictionary
                        loadedtabs[tabitem.Name] = tabitem;
                    }
                    else
                    {
                        String XAPFileName = selectedTreeItem.PageModule + ".xap";
                        WebClient modclient = new WebClient();
                        modclient.OpenReadCompleted += new OpenReadCompletedEventHandler(modclient_OpenReadCompleted);
                        modclient.OpenReadAsync(new Uri(XAPFileName, UriKind.Relative));
                    }

                }
            }
    void modclient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            {
                string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(e.Result, null), 
                    new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd();
                XElement deploymentRoot = XDocument.Parse(appManifest).Root;
                List<XElement> deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements()
                                                  select assemblyParts).ToList();
                Assembly asm = null;
                foreach (XElement xElement in deploymentParts)
                {
                    string source = xElement.Attribute("Source").Value;

                    AssemblyPart asmPart = new AssemblyPart();
                    StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(e.Result, "application/binary"), new Uri(source, UriKind.Relative));
                    ModuleDLL = selectedTreeItem.PageModule + ".dll";
                    ModulePageName = selectedTreeItem.PageModule + "." + selectedTreeItem.PageName;
                    if (source == ModuleDLL)
                    {
                        asm = asmPart.Load(streamInfo.Stream);
                    }
                    else
                    {
                        asmPart.Load(streamInfo.Stream);
                    }
                }
                UIElement myData = asm.CreateInstance(ModulePageName) as UIElement;
                tabitem.Content = myData;
                AppTabGroup.Items.Add(tabitem);
                AppTabGroup.SelectedItem = tabitem;
    //add new tabitem to dictionary
                loadedtabs[tabitem.Name] = tabitem;
            }
    public void RemoveTabItem(RadTabItem currentTab)
            {
    //when the close button is clicked then remove the tabitem from the tabcontrol
    //and next time when this option is selected it will create new instance
                this.AppTabGroup.Items.Remove(currentTab);
                loadedtabs.Remove(currentTab.Name);
            }
    =========================
  13. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 20 Jul 2009 Link to this post

    Hello Srinivas,

    Sorry for not replying sooner,

    Straight to your questions -

    1. Yes, this is one way to cache them. Have in mind though that this way the loaded pages will still be added and removed from the visual tree and their Loaded events will fire, so you need to make sure that you have flagged anything expensive that happens there as well.

    2. The garbage  collector is not very active in Silverlight and it will let Silverlight eat up a lot of memory before starting to collect (at least this is what I notice on my machine, it can be different elsewhere). Objects will be collected from the heap only if there are no more strong references to them. The RemoveTabItem method certainly removes one strong reference, but there could be more strong references that hold the item in memory. A simple way to see when items are collected is to add a breakpoint  / trace in their destructor or Finalzie() method of the objects you expect to be collected. Investigating memory leaks and garbage collection is best done with the WinDbg but IMO not until simpler things have been tried out.

    3. Any place that is visible enough will be fine.

    A simple test for memory leaks is to have a WeakReference that points to one of your objects. Then remove all its know references and call GC.Collect() at least twice. Then check whether the WeakReference is alive. If it is, then most probably this object is leaking.

    Best wishes,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  14. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 20 Jul 2009 Link to this post

    Hello Miroslav,

    Thank you very much for your time and advice. I will take your advice in identifying and fixing the memory issues, if there are any.

    Once again thank you very much for your advice. 

    Regards,
    Srinivas
  15. ewart
    ewart avatar
    221 posts
    Member since:
    Jan 2007

    Posted 05 Jan 2010 Link to this post

    Hi, I found this thread after finding my Loaded event was also being called each time i switched to the tab.  Reading thru the thread I got the impression that the state on each tab was not being stored, as an efficiency measure.

    I quickly discovered it is however it is being preserved in between switching around tabs, just that my loading event was being called each time.  (my loading event preloads listboxes etc from the database so we only want to do this once).  

    So, to avoid the issue, in my control constructor I now set the Loaded event handling:

     

     

     

    public partial class ChooseLocation : UserControl   
    {   
       public ChooseLocation()   
       {  
          this.Loaded += new RoutedEventHandler(ChooseLocation_Loaded);  
       }   
    }  
     
    //..and the first thing I do is remove the handler so it will not be called again from within tabs  
    void ChooseLocation_Loaded(object sender, RoutedEventArgs e)   
    {  
     this.Loaded -= new RoutedEventHandler(ChooseLocation_Loaded);   
       
     // First get a list of countries   
       GetCountries();   
    }  
     
     
     
     
     

     

     

     

     

     

     

     

     

     

     

     

     

    hopefully the tab control does infact preserve state?  if so, this is an easy solution for those all in my scenario.  Hopefully I havn't seriously misunderstood and those values just havn't been garbage collected yet?! 

    cheers
    ewart

     

     

     

     

     

     

     

     

     

     

     

  16. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 05 Jan 2010 Link to this post

    Hello ewart,

    Nope - RadTabControl do not support state at the moment. We have logged this and looking forward on implementing it after Q1.

    Regards,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  17. ewart
    ewart avatar
    221 posts
    Member since:
    Jan 2007

    Posted 05 Jan 2010 Link to this post

    oh thats weird - why is it working for me and on the online demos - in the demos you can see the charts keep their state between tab clicks - and in my app checkboxes and textboxes etc on one tab retain their values when moving around tabs..    is it slow garbage collection?  

    I havn't found any problems yet but have not given it a good thrash either - can I not rely on it working in this way or have I misunderstood you?

    cheers
    ewart.

  18. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 07 Jan 2010 Link to this post

    Hello Еwart,

    There are two ways to fill a TabControl with items - directly in XAML or via binding. If you fill the TabControl with items in XAML (as you probably do in your application and as we do in our charting demo) then the content keeps its state, since the TabControl does not remove the content of its items from the visual tree for performance optimization.
    However, if you give the TabControl a ContentTemplate and bind it to some collection of items, then switching between tabs makes the TabControl unload the content of the last active item and load the content of the newly selected item. This load/unload operations involve add/remove actions in the visual tree, thus the content does not keep its state.

    Let me know how clear this explanations is and if you need further explanation, let me know.

    All the best,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  19. Geoff Hardy
    Geoff Hardy avatar
    58 posts
    Member since:
    Feb 2010

    Posted 05 Mar 2010 Link to this post

    We are using the RadTabControl with its ItemsSource bound to an ObservableCollection of ViewModels. We have found the behaviour of reloading each tab item when you select it to be problematic. One of our tabs contains a RadGridView and if you reload the grid, it resets and does not know which groups were expanded. Another tab contains an RadHtmlPlaceHolder control, and switching back to the tab causes the web page to be reloaded again.

    I have seen some of the possible workarounds for dealing with this, but I would just like to ask if the RadTabControl is likely to support an option to keep the contents of each tab around, and not reload them each time you select a different tab. This would be a very useful feature and we would not have to resort to workarounds.

  20. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 10 Mar 2010 Link to this post

    Hi Geoff Hardy,

    When dealing with MVVM you have to maintain your UI states in the ViewModels. For example when you have GridView on a TabItem you have to keep all the states related to the GridView in the associated ViewModel, like SelectedRow and etc... So when rebinding the Content of the tab everything will look the same as before changing the tabs (the UI state have been preserved in the ViewModels).
    The other option is not to use ViewModels and declare Tabs in XAML, so no rebinding will take place and the UI states would be preserved in the control itself.

    Hope this will help. If you have further questions please contact us.

    All the best,
    Miro Miroslavov
    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.
  21. Geoff Hardy
    Geoff Hardy avatar
    58 posts
    Member since:
    Feb 2010

    Posted 16 Mar 2010 Link to this post

    Thanks for your reply Miroslav. Unfortunately, having to maintain all the UI state in the view model is not a great solution. For example, on our tab we have a RadGridView with grouped rows. If we were to put the state in the ViewModel, we would somehow have to track the following in the ViewModel:
    - which groups are expanded
    - which cell has focus
    I am not sure how these properties can even be bound, we may even have to set them programatically. It seems like a big workaround to deal with the way the RadTabControl recreates its tab page contents all the time. It seems like it would be a very useful enhancement to have a "KeepTabContent" property that would save many developers a lot of hassle.
  22. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 19 Mar 2010 Link to this post

    Hello Geoff Hardy,

    Yes you're right. It's little confusing, but in my opinion for your scenario I'll use statically created tabs with grids and stuff, but will use MVVM for DataContexts for each tab. About KeepTabContent -it'll be weird behavior, but very useful and we'll consider it for new versions. Thank you for the suggestion.
    If you have further questions please contact us.

    Regards,
    Miro Miroslavov
    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.
  23. mark leavesley
    mark leavesley avatar
    56 posts
    Member since:
    Sep 2012

    Posted 01 Apr 2010 Link to this post

    Hello,

    I'm a newbie to Silverlight and the whole Telerik control suite. I've read the previous posts, some of which are beyond me, and I couldn't tell if all the controls in use were SIlverlight or not and therefore relevant to my problem...

    I have an ASP.NET page with a RadTabStrip controlling a RadMultiPage. In one of the pages I have a RadCoverFlow. I have found that the RadCoverFlow is apparently being reloaded from scratch each time it's tab is selected, which makes adding new images on the fly impossible if the user is not looking at that tab. From what I have read this is deliberate behaviour yet the RadGrid and dynamically generated image list in the two other tabs do not loose their content. Extremely confusing.

    These are my Silverlight related files:

    MainPage.xaml

    <UserControl xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  x:Class="SilverlightCoverFlow.MainPage" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" > 
        <Grid Background="AliceBlue" Name="AGrid"
            <telerikNavigation:RadCoverFlow CameraViewpoint="Top" Name="CoverFlow"
                <Image Source="http://127.0.0.1/DOLWeb/Images/Desert.jpg" Stretch="Fill" Width="200" Height="200"/> 
                <Image Source="http://127.0.0.1/DOLWeb/Images/Jellyfish.jpg" Stretch="Fill" Width="200" Height="200"/> 
            </telerikNavigation:RadCoverFlow> 
        </Grid> 
     
    </UserControl> 
     

    MainPage.xaml.vb

    Imports System.Windows.Browser 
    Imports System.Windows.Media.Imaging 
     
    Partial Public Class MainPage 
      Inherits UserControl 
     
      Public Sub New() 
        InitializeComponent() 
     
      End Sub 
     
      Private Sub MainPage_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
        HtmlPage.RegisterScriptableObject("slCoverFlow"Me
     
        Dim so As ScriptObject = TryCast(HtmlPage.Window.Eval("charts"), ScriptObject) 
        so.Invoke("registerSilverlight"
      End Sub 
      <ScriptableMember()> Public Function AddGalleryItem(ByVal strr_ITEM_PATH As StringAs String 
        Dim strl_ERR_MRG As String = "OK" 
        Try 
          Dim objl_IMG As New Image 
          Dim objl_BMP As New BitmapImage 
     
          strl_ERR_MRG = "HERE1" 
          objl_IMG.Height = "200" 
          strl_ERR_MRG = "HERE2" 
          objl_IMG.Width = "200" 
          strl_ERR_MRG = "HERE3" 
          objl_IMG.Stretch = Stretch.Fill 
          strl_ERR_MRG = "HERE4" 
          objl_BMP.UriSource = New Uri(strr_ITEM_PATH) 
          strl_ERR_MRG = "HERE5" 
          objl_IMG.Source = objl_BMP 
          Me.CoverFlow.Items.Add(objl_IMG) 
          strl_ERR_MRG = "HERE6" 
        Catch ex As Exception 
          strl_ERR_MRG = strl_ERR_MRG & ex.Message 
        End Try 
     
        Return strl_ERR_MRG 
      End Function 
      <ScriptableMember()> Public Function Test() As String 
        Return "fred6" 
      End Function 
     
    End Class 

    default.aspx (object tag)

                        <telerik:RadPageView ID="gallery_page" runat="server" Height="506px" Width="100%" > 
                            <div id="silverlightControlHost"
                                <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
                                    width="100%" height="100%" id="silverlightObject"
                                    <param name="source" value="SilverlightCoverFlow.xap" /> 
                                    <param name="onError" value="onSilverlightError" /> 
                                    <param name="background" value="white" /> 
                                    <param name="minRuntimeVersion" value="3.0.40624.0" /> 
                                    <param name="autoUpgrade" value="true" /> 
                                    <param name="onload" value="pluginLoaded" /> 
                                    <param name="windowless" value="true" /> 
                                    <href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration: none"
                                        <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" 
                                            style="border-style: none" /> 
                                    </a> 
                                </object> 
                                <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; 
                                    border: 0px"></iframe
                            </div> 
                            <asp:Label ID="Label1" runat="server"></asp:Label> 
                        </telerik:RadPageView> 
     

    default.aspx (javascript)

                var silverlightControl; 
     
                var charts = { 
                    registerSilverlight: function() { 
                        silverlightControl = document.getElementById('silverlightObject'); 
                        alert("here"); 
                    } 
                } 
     

    What I find is that I get the message 'here' every time I select the tab with the CoverFlow on it and my dynamically added images do not appear. I know that the dynamic code works because if I have JUST the CoverFlow control and nothing else in the page it works.

    A work around for me is for the server to remember what images I am adding and re-populate the CoverFlow control each time it is loaded, but I can't see that being very quick.

    Regards,
    Mark Leavesley
  24. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 01 Apr 2010 Link to this post

    Hello mark leavesley,

    That could happen if you have set the RenderSelectedPageOnly property of the RadMultiPage to True.
    Is that the case?

    You can find attached a sample project. The first tab contains a silverlight control (RadUpload in this case) and the other tabs contain only text. You can switch between them without initializing the silverlight control every time.

    Best wishes,
    Veskoni
    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.
  25. mark leavesley
    mark leavesley avatar
    56 posts
    Member since:
    Sep 2012

    Posted 01 Apr 2010 Link to this post

    Alas no, I have it set to false. I will examine your solution and see what clues that gives me.


    Thanks.
  26. mark leavesley
    mark leavesley avatar
    56 posts
    Member since:
    Sep 2012

    Posted 04 Apr 2010 Link to this post

    This is a VS2010 solution. Whilst I have this, the solution loads with errors in the designer.

    I am baffled why you are providing solutions in such a new version of VS, I imagine many developers would not be prepared to install this yet.

    Any idea why I am getting designer errors? Probably related, a VS 2008 solution that works in the office shows fine in the designer here but in the web page the RADGrid has lost all visual presence, it's just a pile of text and links. The only difference is that at work it's Windows 7 x86 but here it's x64. Same versions of VS 2008, Windows 7, Telerik controls (trial versions).

    Regards,
    Mark Leavesley
  27. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 08 Apr 2010 Link to this post

    Hi Mark leavesley,

    Could you please check this help article which explains how to fix design-time issues? Let us know how it goes.

    Regards,
    Yana
    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.
  28. mark leavesley
    mark leavesley avatar
    56 posts
    Member since:
    Sep 2012

    Posted 08 Apr 2010 Link to this post

    Hello,

    I did have this initially but fixed it by installing SP1. I get design time errors in VS2010 using the sample previously attached. In VS2008 design time is fine but in the browser the RadGrid has 'gracefully degraded' to just text, and the RadTextBoxes are fine. I will attach an image when I get home...


    Regards,
    Mark Leavesley
  29. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 09 Apr 2010 Link to this post

    Hello Mark,

    We're waiting for the screenshot. Thanks

    Best wishes,
    Yana
    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.
  30. mark leavesley
    mark leavesley avatar
    56 posts
    Member since:
    Sep 2012

    Posted 09 Apr 2010 Link to this post

    Hello,

    Attached are two images, one showing the designer and one showing the page in Google Chrome (Chrome works fine in the office). As you can see the multipage and the radgrid have deteriorated, but the textboxes are fine. I have also tried installing the latest Telerik build, didn't make any difference. I can supply the generated HTML as well though there is a lot of it!

    EDIT: Updated my home copy of the source, updated the controls, restarted VS2008 and now I get as shown in the 2nd VS2008 image. Also got popup error messages about the cast errors.


    Regards,
    Mark Leavesley
  31. mark leavesley
    mark leavesley avatar
    56 posts
    Member since:
    Sep 2012

    Posted 09 Apr 2010 Link to this post

    2nd VS2008 image, additional attachments don't upload when you edit your post.
Back to Top
DevCraft banner