This is probably a basic WPF question, and not specifically Telerik related, but I figured I'd ask here. I am trying to create a reusable control, right now named SectionLayout, which allows the user of the control to define "sections", with Visuals in each section. I want to render this using RadTabControl.
Basically, the consumer of the SectionLayout would be using it like this:
I've already got most of it working. SectionLayout has a "Sections" property, of type SectionCollection, that holds items of type Section. Section has Name and Content properties. Name is a string, Content is an object.
The ControlTemplate for SectionLayout currently looks like this:
So, basically I'm just making an easier interface to use a RadTabControl. So I can reuse it in other places. Though it might change from being a RadTabControl to something else in the future.
The problem I'm having is getting the original DataContext of Section.Content property to flow into the RadTabControl.ContentTemplate. The ContentTemplate is of course given the business object (Section) as it's datacontext. So, I can easily present Section.Content. However, when I do so, Section.Content begins inheriting the DataContext given to it by the ContentPresenter, which happens to be Section.Content.
How can I do this properly? I want the user to be able to use my control as he would any normal layout control: Grid, Canvas, StackPanel, whatever. But, I need to use a TabControl internally to do the layout.
Basically, the consumer of the SectionLayout would be using it like this:
<
local:SectionLayout
>
<
local:Section
Name
=
"Foo"
>
<
Button
Text
=
"{Binding Foo}"
/>
</
local:Section
>
</
local:SectionLayout
>
I've already got most of it working. SectionLayout has a "Sections" property, of type SectionCollection, that holds items of type Section. Section has Name and Content properties. Name is a string, Content is an object.
The ControlTemplate for SectionLayout currently looks like this:
<
ControlTemplate
>
<
telerik:RadTabControl
Align
=
"Right"
TabOrientation
=
"Vertical"
TabStripPlacement
=
"Left"
ItemsSource
=
"{TemplateBinding Sections}"
>
<
telerik:RadTabControl.ItemContainerStyle
>
<
Style
TargetType
=
"{x:Type telerik:RadTabItem}"
>
<
Setter
Property
=
"MinHeight"
Value
=
"150"
/>
<
Setter
Property
=
"MinWidth"
Value
=
"30"
/>
</
Style
>
</
telerik:RadTabControl.ItemContainerStyle
>
<
telerik:RadTabControl.ItemTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
</
telerik:RadTabControl.ItemTemplate
>
<
telerik:RadTabControl.ContentTemplate
>
<
DataTemplate
DataType="{x:Type local:Section}">
<
ContentPresenter
Margin
=
"4,4,4,4"
DataContext
=
"{TemplateBinding DataContext}"
Content
=
"{Binding Content}"
/>
</
DataTemplate
>
</
telerik:RadTabControl.ContentTemplate
>
</
telerik:RadTabControl
>
</
ControlTemplate
>
So, basically I'm just making an easier interface to use a RadTabControl. So I can reuse it in other places. Though it might change from being a RadTabControl to something else in the future.
The problem I'm having is getting the original DataContext of Section.Content property to flow into the RadTabControl.ContentTemplate. The ContentTemplate is of course given the business object (Section) as it's datacontext. So, I can easily present Section.Content. However, when I do so, Section.Content begins inheriting the DataContext given to it by the ContentPresenter, which happens to be Section.Content.
How can I do this properly? I want the user to be able to use my control as he would any normal layout control: Grid, Canvas, StackPanel, whatever. But, I need to use a TabControl internally to do the layout.