rastro

I¡¯m trying to build a WPF TabControl with built-in scrolling to create an effect similar to Microsoft Excel. I started with a TabControl style and added ScrollBars. I then changed ContentPresenter to ScrollContentPresenter (presumably to get the IScrollInfo interface). What I don¡¯t understand is how to bind the ScrollBar properties to the changing SelectedContent. Please see highlighted areas in attached code. Any help is greatly appreciated. Is there a better approach Has this already been done

Code Snippet

<Style TargetType="{x:Type TabControl}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border
Name="Border"
Grid.Row="0"
BorderThickness="1"
CornerRadius="0"
Background="{StaticResource WindowBackgroundBrush}"
BorderBrush="{StaticResource SolidBorderBrush}"
KeyboardNavigation.TabNavigation="Local"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2" Grid.ColumnSpan="3" >
<ScrollContentPresenter
Name="PART_SelectedContentHost"
Margin="0"
ContentSource="SelectedContent" />

</Border>
<TabPanel
Name="HeaderPanel"
Grid.Row="1"
Grid.RowSpan="1"
Grid.ColumnSpan="1"
Panel.ZIndex="1"
Margin="0,-1,4,10"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="Transparent"
VerticalAlignment="Top" />
<ScrollBar Name="PART_HorizontalScrollBar"
Orientation="Horizontal"
Grid.Row="1"
Grid.Column="2"
Value="{TemplateBinding ContentControl.HorizontalOffset}"
Maximum="{TemplateBinding ScrollableWidth}"
ViewportSize="{TemplateBinding ViewportWidth}"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>



Re: Windows Presentation Foundation (WPF) TabControl with built-in scrolling

Ramanujam Sampath

Hi,

How about using a ScrollViewer and moving in other controls into the scroll viewer. I am not sure if this surely helps, but worth a try i believe.

~Ram






Re: Windows Presentation Foundation (WPF) TabControl with built-in scrolling

rastro

Thanks for the idea, but I think we're still left with the same problem - being able to identify the changing TabControl content by the ScrollBars.

You could build a custom control from scratch. You could modify the tab control style so content didn't change with the tabs, and then use a click event to invoke the change. You could extend the content area of the tab control to the second row of the grid to transparently locate the horizontal scroll bar to the right of the tabs.

I was hoping for a cleaner solution. Perhaps someone from MS could explain the inner workings of ContentPresenter vs. ScrollContentPresenter and how they can be bound within a template.





Re: Windows Presentation Foundation (WPF) TabControl with built-in scrolling

lee d

try

<ScrollViewer

Name="PART_SelectedContentHost"

Margin="4"

>

<ContentControl Content="{TemplateBinding SelectedContent}"></ContentControl>

</ScrollViewer>






Re: Windows Presentation Foundation (WPF) TabControl with built-in scrolling

Ramanujam Sampath

the IRONY here is, this is what i meant when i said use ScrollViewer and put the content inside the scrollviewer... !!! Smile

~Ram






Re: Windows Presentation Foundation (WPF) TabControl with built-in scrolling

rastro

Thanks for the idea. That does work, but still doesn't merge the tab and horizontal scrollbar rows. In other words, the scrollbar appears in a separate row above the tabs. I was hoping someone (perhaps MS) knew of some binding method that would make the selected item's properties available within the template.



Re: Windows Presentation Foundation (WPF) TabControl with built-in scrolling

Ramanujam Sampath

<TabControl Height="200" Width="300">
<TabItem Header="ABC">
<ScrollViewer Height="160" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<RichTextBox Height="600" Width="900"/>
</ScrollViewer>
</TabItem>
<TabItem Header="ABC"/>
</TabControl>

I was able to scroll thro the richtextbox automatically. As and when I press enter the scroll also moves to show the right mouse pointer. I hope this wil work with a template too. Please let us know if we r missing something here

Thanks,

Ram