0

Hi,
I´ve got following code for a office 2010 like tabcontrol in .NET 4.0

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ControlTemplate x:Key="OfficeTabControl" TargetType="{x:Type TabControl}">
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabItem}">
                            <Grid SnapsToDevicePixels="True">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup Name="CommonStates">
                                        <VisualState Name="MouseOver">
                                            <Storyboard>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="hoverShape" 
                                                    Storyboard.TargetProperty="Opacity" 
                                                    To="1" 
                                                    Duration="0:0:.1"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState Name="Normal">
                                            <Storyboard>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="hoverShape" 
                                                    Storyboard.TargetProperty="Opacity" 
                                                    To="0"
                                                    Duration="0:0:.1"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup Name="SelectionStates">
                                        <VisualState Name="Selected">
                                            <Storyboard>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="buttonShape" Storyboard.TargetProperty="Opacity" 
                                                    To="1" Duration="0:0:.3"/>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="buttonBackgroundShape" 
                                                    Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="hoverShape" Storyboard.TargetProperty="Opacity" 
                                                    To="0" Duration="0:0:.1"/>
                                                <ColorAnimation 
                                                    Storyboard.TargetName="buttonText" 
                                                    Storyboard.TargetProperty="(TextBlock.Foreground).(Color)" 
                                                    To="White" Duration="0:0:.1" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState Name="Unselected">
                                            <Storyboard>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="buttonShape" 
                                                    Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.1"/>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="buttonBackgroundShape" 
                                                    Storyboard.TargetProperty="Opacity" To="0" Duration="0"/>
                                                <DoubleAnimation 
                                                    Storyboard.TargetName="hoverShape" 
                                                    Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.1"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border Name="hoverShape"
                                        Height="40"
                                        Margin="0,0,0,0" 
                                        SnapsToDevicePixels="True" 
                                        BorderThickness="0,0,1,0" 
                                        BorderBrush="LightGray">
                                    <Border BorderBrush="#FFA1B7EA"
                                            BorderThickness="0,1" 
                                            Background="#FFE5EEF9" 
                                            Height="40" 
                                            SnapsToDevicePixels="True" />
                                </Border>
                                <Rectangle Name="buttonBackgroundShape" 
                                           Stretch="Fill" Opacity="0" 
                                           Fill="White" Height="40" SnapsToDevicePixels="True" />
                                <Border 
                                    Name="buttonShape" 
                                    Opacity="0" 
                                    BorderBrush="#FF0343A6" 
                                    BorderThickness="0,2" 
                                    Height="40"
                                    SnapsToDevicePixels="True">
                                    <Path 
                                        Data="M214,108 L346,108 L346,125 L214,125 z"
                                        SnapsToDevicePixels="True" 
                                        Stretch="Fill"
                                        Height="40">
                                        <Path.Fill>
                                            <RadialGradientBrush GradientOrigin="0.2,0.5" RadiusX="0.8" RadiusY="0.8">
                                                <GradientStop Color="#FF5FA3F6" Offset="0" />
                                                <GradientStop Color="#FF0C55B9" Offset="1" />
                                            </RadialGradientBrush>
                                        </Path.Fill>
                                    </Path>
                                </Border>
                                <ContentPresenter 
                                    Name="buttonText"
                                    Margin="15,0,5,0" 
                                    TextBlock.FontFamily="Calibri" 
                                    TextBlock.FontSize="12pt" 
                                    TextBlock.Foreground="Black" 
                                    Content="{TemplateBinding Header}"
                                    VerticalAlignment="Center"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ControlTemplate.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="160" />
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border Background="#FFE9ECEF" 
                    Grid.Column="0" 
                    BorderBrush="LightGray" 
                    BorderThickness="1" 
                    SnapsToDevicePixels="True" />
            <StackPanel IsItemsHost="True"
                        Grid.Column="0"
                        Margin="0,0,0,0" 
                        SnapsToDevicePixels="True" />
            <ContentPresenter 
                Content="{TemplateBinding SelectedContent}" 
                Grid.Column="1" 
                Margin="15,0,0,0" />
        </Grid>
    </ControlTemplate>
</ResourceDictionary>

The usage is like following

<Window x:Class="lay.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="OfficeTab.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <TabControl Name="Categories" Template="{StaticResource OfficeTabControl}">
            <TabItem Header="First"></TabItem>
            <TabItem Header="Second"></TabItem>
            <TabItem Header="Third"></TabItem>
        </TabControl>
    </Grid>
</Window>

The problem is that "VisualstateManager" and "Visualstate" aren´t existing in .NET Framework 3.5.
I already tried using the WPF toolkit for 3.5 but it aint´working

Could someone please help me converting this to .NET 3.5?
Thanks in advance,
Eric

Edited by exicar: n/a

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by nmaillet
0

The only reason you are able to use the default .NET controls, is since http://schemas.microsoft.com/winfx/2006/xaml/presentation is declared as the default namespace. Otherwise you have to explicitly state a namespace alias; for instance, x:Key. Since VisualStateManager is not included in .NET 3.5, you'll have to add a reference to it.

I don't know how the exact namespace or assembly name of the WPF Toolkit off the top of my head, but you add an attribute to the ResourceDictionary similar to this:

xmlns:data="clr-namespace:System.Data;assembly=System"

Then reference it like:

<data:DataSet>
...
</data:DataSet>

Edited by nmaillet: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.