TabControl with Custom ContentTemplate not redrawing

4 posts, 0 answers
  1. David Romanchuk
    David Romanchuk avatar
    5 posts
    Member since:
    Dec 2009

    Posted 21 Dec 2009 Link to this post

    I have a RadTabControl with a Custom ContentTemplate. It works fine, and displays the content as I'd expect when first viewing the tab. However, when changing from one tab, back to the original tab, I find that the data inside the content presenter is no longer being displayed. It appears as if the DataContext or ItemsSource binding is no longer being applied as I'd expect.

    Below is a short expample which should illustrade what I'm seeing. I'm using MVVM, and the ClosedOrderCol in the code snippet below is an ObservableCollection on the ViewModel.

    Any help would be appreciated.

    <Navigation:RadTabControl> 
                <Navigation:RadTabControl.ItemContainerStyle> 
                        <Setter Property="ContentTemplate"
                            <Setter.Value> 
                                <DataTemplate>
                                    <Grid>
                                       <ContentPresenter Content="{TemplateBinding Content}"/>
                                    </Grid>
                                </DataTemplate> 
                            </Setter.Value> 
                        </Setter> 
                </Navigation:RadTabControl.ItemContainerStyle> 
                <Navigation:RadTabItem> 
                        <Controls:RadGridView Grid.Row="1" ItemsSource="{Binding ClosedOrderCol}" IsReadOnly="True"
                            <Controls:RadGridView.Columns>                        
                               <Controls:GridViewDataColumn Header="Closed" DataMemberBinding="{Binding DateClosed}" /> 
                            </Controls:RadGridView> 
                </Navigation:RadTabItem> 
                <Navigation:RadTabItem /> 
    <Navigation:RadTabControl> 

  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 28 Dec 2009 Link to this post

    Hello David Romanchuk,

    The DataTemplate properties on the controls are used to set a template for how the business objects should be visually presented. If you set the Content of a TabItem directly (as in the code sample), a ContentTemplate is not needed since there is no doubt as to how the GridView should be presented.

    If you remove the ItemContaienrStyle in this case everything will work as expected. 

    All the best,
    Miroslav
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David Romanchuk
    David Romanchuk avatar
    5 posts
    Member since:
    Dec 2009

    Posted 05 Jan 2010 Link to this post

    I think I may have over-simplified my example, but I agree it appears that ItemContainerStyle's ContentTemplate is perhaps the wrong thing to template in this case.

    My end goal is to apply rounded corners to the bottom of the content in all of my tab items. Applying the template below achieves the desired effect, but has the undesirable effect of causing issues displaying data when navigating between tabitems as mentioned in the original post.

    Is there another way I'm missing that I can template how the content of all my tab items is displayed?

        <DataTemplate x:Key="TabItemTemplate"
            <Border BorderThickness="1,0,1,1" CornerRadius="0,0,5,5"
                <Grid> 
                    <Border x:Name="TabItemMask"BorderThickness="1,0,1,1" CornerRadius="0,0,5,5" /> 
                    <Grid> 
                        <Grid.OpacityMask> 
                            <VisualBrush Visual="{Binding ElementName=TabItemMask}"/> 
                        </Grid.OpacityMask> 
                        <ContentPresenter Content="{TemplateBinding Content}" />  
                    </Grid> 
                </Grid> 
            </Border> 
        </DataTemplate> 


  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 08 Jan 2010 Link to this post

    Hello David,

    To achieve what you are looking for depends on whether your TabControl is bound or you define the TabItems in XAML. If your TabControl is bound, then you can use the DataTemplate you've previously mentioned and give it as ContentTemplate to TabControl. If, on the other hand, your TabControl is not bound, you will have to edit the ControlTemplate of the TabControl and modify it according to your preferences. I have attached a sample project that demonstrates both approaches. When you open Window1.xaml, at line 34 you will find the place where you can modify the borders as you wish. Give it a try and let me know how it works for you.

    Regards,
    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.
Back to Top