This is a migrated thread and some comments may be shown as answers.

TabControl with Custom ContentTemplate not redrawing

3 Answers 359 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
David Romanchuk
Top achievements
Rank 1
David Romanchuk asked on 21 Dec 2009, 10:51 PM
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> 

3 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 28 Dec 2009, 10:34 AM
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.
0
David Romanchuk
Top achievements
Rank 1
answered on 05 Jan 2010, 11:40 PM
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> 


0
Kiril Stanoev
Telerik team
answered on 08 Jan 2010, 10:41 AM
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.
Tags
TabControl
Asked by
David Romanchuk
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
David Romanchuk
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Share this question
or