Ignazio Catanzaro

Sviluppatore Software

C# .Net

Archivio Posts
Anno 2012

Anno 2011

Anno 2010
Sondaggio
Introdurre argomenti di software engineering in un blog può essere utile?

Si
No

Customed TabControl in poche righe di codice!

Salve a tutti!

Oggi, un piccolissimo post per dimostrare la potenza di WPF!


Come molti di voi sapranno, WPF è un framework che diviene sempre piu popolare tra noi sviluppatori, offre potenza con una relativa semplicità d'uso che quasi disarma!

In questo "tips of the day" dimostrerò come con pochissimi righe di XAML sia possibile ottenere un'effetto del genere :


P.S, sono le 00.58 ho appena finito di lavorare e questa è la cosa piu fantasiosa che mi sia venuta in mente! :D

E' possibile ottenere quell'effetto utilizzando uno stile semplicissimo per il controllo tabItem (per semplicità potete inserirlo nell App.xaml del progetto) :

 <Application.Resources>
        <Style TargetType="{x:Type TabItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <Grid>
                            <Border 
             Name="Border"
             Background="LightBlue"
             BorderBrush="Black" 
             BorderThickness="1,1,1,1" 
             CornerRadius="8,8,0,0" 
                                Margin="-2,0,2.5,-3">
                                <ContentPresenter x:Name="ContentSite"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               ContentSource="Header"
               Margin="12,2,12,2"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="Border" Property="Background" Value="azure" />
                                <Setter TargetName="Border" Property="BorderThickness" Value="3,2,2,0" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="#FF5E7090" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="False">
                                <Setter TargetName="Border" Property="Background" Value="LightGray" />
                                <Setter TargetName="Border" Property="BorderThickness" Value="2,1,1,2" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="#FF5E7090" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Application.Resources>

Ora, create un tabControl con le seguenti caratteristiche nella mainWindow, ed utilizzate i tabItem per aggiungere linguette al controllo :

<TabControl Height="287" HorizontalAlignment="Left" Margin="12,12,0,0" Name="tabControl1" VerticalAlignment="Top" Width="479" Background="azure" BorderThickness="3" BorderBrush="#FF5E7090">

Esempio : 


Semplice no?


Stay Tuned ;)
Categoria: Framework .Net
giovedì, 08 apr 2010 Ore. 01.06

Calendario
aprile 2024
lmmgvsd
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
Ora e Data
Statistiche
  • Views Home Page: 32.323
  • Views Posts: 44.988
  • Views Gallerie: 0
  • n° Posts: 24
  • n° Commenti: 12
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003