Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
is this a best practice in wpf

<TabControl x:Name="tabMain"
                            BorderThickness="1"
                            Grid.Row="0"
                            Grid.RowSpan="2"    
                            IsSynchronizedWithCurrentItem="True"
                            Margin="0"
                            Padding="0"
                            
                            Background="#FFFFFF"
                            
                            >
            <TabControl.Resources>
                <Style x:Key="tabcontrol"
                               TargetType="local:cTabitem">
                    <!--<Setter Property="FontFamily"
                                    Value="{StaticResource SegoSemiboldFont}" />-->
                    <Setter Property="FontSize"
                                    Value="15" />
                    <Setter Property="Margin"
                                    Value="1 -4  0 0" />
                    <Setter Property="Padding"
                                    Value="0" />
                    <Setter Property="Cursor"
                                    Value="Hand" />
                    
                    <Setter Property="Width"
                                    Value="{Binding}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="local:cTabitem">
                                <Border x:Name="Border"
                                                BorderThickness="1"
                                                
                                                Height="65"
                                                Background="#ECECEC">
                                    
                                    <Grid>
                                        <StackPanel Orientation="Vertical"
                                                            HorizontalAlignment="Center"
                                                            VerticalAlignment="Top"
                                                            x:Name="stack" >
                                            <Image x:Name="img"
                                                           Source="{Binding SelectedImage, RelativeSource={RelativeSource TemplatedParent}}"
                                                           RenderOptions.BitmapScalingMode="HighQuality"
                                                           RenderOptions.EdgeMode="Aliased"
                                                           SnapsToDevicePixels="True"
                                                           VerticalAlignment="Top"
                                                           Stretch="None" ></Image>
                                            <!--<StackPanel.ToolTip>
                                                <ContentPresenter x:Name="ContentSites"
                                                                          Margin="5,0"
                                                                          VerticalAlignment="Center"
                                                                          HorizontalAlignment="Center"
                                                                          ContentSource="Header">
                                                </ContentPresenter>
                                            </StackPanel.ToolTip>-->
                                            <Label x:Name="lbl_headText" Foreground="Black" FontSize="11" Width="{TemplateBinding Width}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Padding="0 5" HorizontalContentAlignment="Center" FontWeight="Bold" >
                                                <ContentPresenter x:Name="lbl_ContentSites"
                                                                          Margin="0 0 0 12"
                                                                          VerticalAlignment="Center"
                                                                          HorizontalAlignment="Center"
                                                                          ContentSource="Header">
                                                </ContentPresenter>
                                            </Label>
                                        </StackPanel>
                                        
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <!--<Trigger Property="IsSelected"
                                                     Value="True">
                                        <Setter TargetName="Border"
                                                        Property="Background"
                                                        Value="#ECECEC" />
                                        
                                        <Setter TargetName="lbl_headText"
                                                        Property="Foreground"
                                                        Value="Black" />
                                        --><!--<Setter TargetName="Border"
                                                        Property="BorderBrush"
                                                        Value="{x:Static local:cImageResources.clLinks}" />-->
                                        <!--<Setter TargetName="Border"
                                                        Property="BorderThickness"
                                                        Value="0,1,0,0" />--><!--
                                        <Setter TargetName="img"
                                                        Property="Source"
                                                        Value="{Binding SelectedImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Trigger>
                                    <Trigger Property="IsSelected"
                                                     Value="False">
                                        <Setter TargetName="Border"
                                                        Property="Background"
                                                        Value="#141414" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Foreground"
                                                        Value="#A6A6A6" />
                                        <Setter TargetName="img"
                                                        Property="Source"
                                                        Value="{Binding NormalImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Trigger>
                                    <Trigger Property="IsMouseOver"
                                                     Value="True">
                                        <Setter TargetName="Border"
                                                        Property="Background"
                                                        Value="#141414" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Foreground"
                                                        Value="White" />
                                        <Setter TargetName="img"
                                                        Property="Source"
                                                        Value="{Binding SelectedImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Trigger>-->

                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition  Property="IsMouseOver"
                                                                Value="True" />
                                            <Condition Property="IsTabStop"
                                                               Value="True" />
                                            <Condition Property="IsSelected" Value="true"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="Border"
                                                        Property="Background"
                                                        Value="#F1F1F1" />
                                        <Setter TargetName="img"
                                                        Property="Source"
                                                        Value="{Binding SelectedImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Foreground"
                                                        Value="Black" />
                                    </MultiTrigger>

                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition  Property="IsMouseOver"
                                                                Value="True" />
                                            
                                            <Condition Property="IsSelected" Value="false"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="Border"
                                                        Property="Background"
                                                        Value="#F1F1F1" />
                                        <Setter TargetName="img"
                                                        Property="Source"
                                                        Value="{Binding HoverImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Foreground"
                                                        Value="White" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Background"
                                                        Value="#000000" />
                                        <Setter TargetName="Border" Property="Background" Value="#414040"/>
                                    </MultiTrigger>

                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition  Property="IsMouseOver"
                                                                Value="false" />

                                            <Condition Property="IsSelected" Value="false"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="Border"
                                                        Property="Background"
                                                        Value="#F1F1F1" />
                                        <Setter TargetName="img"
                                                        Property="Source"
                                                        Value="{Binding NormalImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Foreground"
                                                        Value="White" />
                                        <Setter TargetName="lbl_headText"
                                                        Property="Background"
                                                        Value="#000000" />
                                        <Setter TargetName="Border" Property="Background" Value="#343434"/>
                                    </MultiTrigger>


                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    
                </Style>

                <Style TargetType="{x:Type TabPanel}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                </Style>
            </TabControl.Resources>
            <local:cTabitem Header="Status"
                                   Width="102" 
                                    
                                    Style="{StaticResource tabcontrol}"
                                    x:Name="tboverview"                                      
                                    NormalImage="/Wpftabtest;component/Resources/Home1.png"
                                    SelectedImage="/Wpftabtest;component/Resources/Home2.png"
                                    HoverImage ="/Wpftabtest;component/Resources/Home3.png">
                
            </local:cTabitem>

            <local:cTabitem Style="{StaticResource tabcontrol}"
                                   Width="102" 
                                    Header="Driver Scan"
                                    x:Name="tbScan"
                                    NormalImage="/Wpftabtest;component/Resources/DriverScan1.png"
                                    SelectedImage="/Wpftabtest;component/Resources/DriverScan2.png"
                                    HoverImage ="/Wpftabtest;component/Resources/DriverScan3.png">
                
            </local:cTabitem>

            <local:cTabitem x:Name="tbWebProtection"
                                   Width="102" 
                                    Style="{StaticResource tabcontrol}"
                                    Header="Backup"
                                    NormalImage="/Wpftabtest;component/Resources/Backup1.png"
                                    SelectedImage="/Wpftabtest;component/Resources/Backup2.png"
                                    HoverImage ="/Wpftabtest;component/Resources/Backup3.png">
                
            </local:cTabitem>

            <local:cTabitem x:Name="tbStartupManager"
                                    Width="102" 
                                    Style="{StaticResource tabcontrol}"
                                    Header="Restore"
                                    NormalImage="/Wpftabtest;component/Resources/Restore1.png"
                                    SelectedImage="/Wpftabtest;component/Resources/Restore2.png"
                                    HoverImage ="/Wpftabtest;component/Resources/Restore3.png">
                
            </local:cTabitem>
            <local:cTabitem x:Name="tbActionCenter"
                                   Width="102" 
                                    Style="{StaticResource tabcontrol}"
                                    Header="Settings"
                                    NormalImage="/Wpftabtest;component/Resources/Settings1.png"
                                    SelectedImage="/Wpftabtest;component/Resources/Settings2.png"
                                    HoverImage ="/Wpftabtest;component/Resources/Settings3.png">
                
            </local:cTabitem>
            <local:cTabitem x:Name="tbRegistration"
                                    Width="102" 
                                    Style="{StaticResource tabcontrol}"
                                    Header="Register Now"
                                    NormalImage="/Wpftabtest;component/Resources/register1.png"
                                    SelectedImage="/Wpftabtest;component/Resources/register2.png"
                                    HoverImage ="/Wpftabtest;component/Resources/register3.png">
                
            </local:cTabitem>

           

            <!--<local:cTabitem Style="{StaticResource tabcontrol}"
                                    Header=""
                                    x:Name="tabExtra"
                                    Width="0"
                                    Cursor="Arrow"
                                    IsTabStop="False">
                
            </local:cTabitem>-->

        </TabControl>


What I have tried:

TabControl x:Name="tabMain"
                            BorderThickness="1"
                            Grid.Row="0"
                            Grid.RowSpan="2"    
                            IsSynchronizedWithCurrentItem="True"
                            Margin="0"
                            Padding="0"
                            
                            Background="#FFFFFF"
                            
                            >
Posted
Updated 23-Nov-18 2:11am
Comments
Dirk Bahle 23-Nov-18 7:50am    
Not sure whaz your problem is - woud you care to explain your problem?

1 solution

Dumping code with a throw away question
Quote:
is this a best practice in wpf
is not a good question. It is so vague we cannot possibly answer it. It is not clear what "practice" you are referring to - it could be anything from
- your naming conventions (looks ok to me, at least you haven't used default names)
- to the use of indentation in the source code file (common practice)
- through to the use of data binding (yes, this is good practice)

You can find out more about "best practices" with a little research - try Google[^] or by reading books like The Pragmatic Programmer[^] or Code Complete[^] (there are others)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900