srilekhamenon Ответов: 1

Лучшая практика Xaml в WPF


является ли это лучшей практикой в 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>


Что я уже пробовал:

TabControl x:Name="tabMain"
                            BorderThickness="1"
                            Grid.Row="0"
                            Grid.RowSpan="2"    
                            IsSynchronizedWithCurrentItem="True"
                            Margin="0"
                            Padding="0"
                            
                            Background="#FFFFFF"
                            
                            >

Dirk Bahle

Не уверен, в чем ваша проблема - не хотите ли вы объяснить свою проблему?

1 Ответов

Рейтинг:
1

CHill60

Демпинг кода с помощью выброшенного вопроса

Цитата:
является ли это лучшей практикой в wpf
это не очень хороший вопрос. Она настолько расплывчата, что мы не можем на нее ответить. Непонятно, какую "практику" вы имеете в виду - это может быть что угодно от
- ваши соглашения об именах (мне кажется, все в порядке, по крайней мере, вы не использовали имена по умолчанию)
- к использованию отступов в файле исходного кода (обычная практика)
- вплоть до использования привязки данных (да, это хорошая практика)

Вы можете узнать больше о "лучших практиках" с помощью небольшого исследования - попробуйте Гугл[^] или читая такие книги, как Прагматичный Программист[^] или Полный Код [^] (есть и другие)