VisualStates and TabControl

4 posts, 0 answers
  1. P
    P avatar
    3 posts
    Member since:
    Jan 2012

    Posted 29 Feb 2012 Link to this post

    Hi,

    Does the RadTabControl not work with VisualStates?

    I have several tabs with different content in them and using Expression Blend modified a Visual State so that on one of the RadTabItems a child buttons visibility is set to collapsed in order to hide it.

    I find that this can cause exceptions to be thrown in Expression Blend when I move to a different tab. Within the application I am using property triggers and GoToStateAction class to change to the visual state. When this happens I get a first chance exception - InvalidOperationException : 'Cannot Resolve TargetName btnSaveCertificates'.

    Looking through the telerik documentation it seems that the reason for this is that as the user moves between tabs it is only the active tab whose content is displayed and part of the Visual Tree because only a single content presenter is being used by the RadTabControl. Hence even though the button to be hidden is visible within the xaml, it is only part of the Visual Tree when its parent Tab is active.

    I have looked at the IsContentPreserved property of the RadTabControl setting it to true, but when I run the application the tabs contents are blank. Is the idea behind this property that all of the TabItems content is loaded into the VisualTree so that it can be accessible by VisualStates?

    Please advise.

    Cheers
    pb
  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 02 Mar 2012 Link to this post

    Hi,

    IsContentPreserved property provides ContentPresenter for every TabItem content (more precisely, every previously selected  item). Thus when you select particular item its content will be inserted into the visual tree via dedicated content presenter. When next item is selected, its content will be inserted dynamically into the visual tree again via dedicated content presenter and the previously visible content will be collapsed.

    So if all tab items have been selected, their content will be part of the visual tree. If item has not yet been selected its content won't be in the visual tree.

    Hope this helps.

    Regards,
    Hristo
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. P
    P avatar
    3 posts
    Member since:
    Jan 2012

    Posted 02 Mar 2012 Link to this post

    Hi Hristo,

    Thanks for the reply.

    So would the best option be to programmatically select each tab in turn to force the control to load all the content. Perhaps doing this once in the controls LayoutUpdated event?

    Kind Regards
    pb
  5. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 06 Mar 2012 Link to this post

    Hi,

    What you are suggesting is to select every item when TabControl is initialized and rendered. Doing this on LayoutUpdated sounds reasonable. However, you should keep in mind that this will degrade the performance during initial load.
    My personal advise would be to use data binding and change the visibility in you view model. When selecting new tab its content (button) visibility shall be retrieved from the view model via binding.
    If you are limited and could not use binding, selecting programmatically every tab is the approach you should employ.

    All the best,
    Hristo
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top