IconPack: значок FontAwesome исчезает в пользовательском TabItem - PullRequest
0 голосов
/ 15 ноября 2018

Новичок в WPF и, возможно, некоторое время назад совершил неправильный поворот, но у меня все работает до сих пор, просто «иконка» TabItem не остается после перехода на другую вкладку.Он исчезает, как будто у нас есть только одна кнопка закрытия.

<UserControl.Resources>
    <Style BasedOn="{StaticResource {x:Type Controls:Tile}}" TargetType="Controls:Tile" x:Key="ClosableTabButton">
        <Setter Property="Width"
                Value="17"/>
        <Setter Property="Height"
                Value="17"/>
        <Setter Property="Content">
            <Setter.Value>
                <iconPacks:PackIconFontAwesome Margin="0,0,0,0" 
                                                       Width="15"
                                                       Height="15"
                                                       Kind="PlusCircleSolid" 
                                                       Rotation="45"
                                                       RenderTransformOrigin="0.5,0.5"
                                                       Foreground="#FFFFFF">
                </iconPacks:PackIconFontAwesome>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Content">
                    <Setter.Value>
                        <iconPacks:PackIconFontAwesome Margin="0,0,0,0" 
                                                            Width="15"
                                                            Height="15"
                                                            Kind="PlusCircleSolid" 
                                                            Rotation="45"
                                                            RenderTransformOrigin="0.5,0.5"
                                                            Foreground="#ff0000">
                        </iconPacks:PackIconFontAwesome>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

Это мой пользовательский тайл для иконки / кнопки.

<Grid>
    <TabControl Name="tabControl" ItemsSource="{Binding}" SelectionChanged="tabControl_SelectionChanged">
        <TabControl.Template>
            <ControlTemplate TargetType="{x:Type TabControl}">
                <Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Name="ColumnDefinition0"/>
                        <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition x:Name="RowDefinition0" Height="Auto"/>
                        <RowDefinition x:Name="RowDefinition1" Height="*"/>
                    </Grid.RowDefinitions>
                    <WrapPanel x:Name="headerPanel" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/>
                    <Border x:Name="contentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
                        <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="TabStripPlacement" Value="Bottom">
                        <Setter Property="Grid.Row" TargetName="headerPanel" Value="1"/>
                        <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
                        <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
                        <Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
                        <Setter Property="Margin" TargetName="headerPanel" Value="2,0,2,2"/>
                    </Trigger>
                    <Trigger Property="TabStripPlacement" Value="Left">
                        <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
                        <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
                        <Setter Property="Grid.Column" TargetName="headerPanel" Value="0"/>
                        <Setter Property="Grid.Column" TargetName="contentPanel" Value="1"/>
                        <Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
                        <Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
                        <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
                        <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
                        <Setter Property="Margin" TargetName="headerPanel" Value="2,2,0,2"/>
                    </Trigger>
                    <Trigger Property="TabStripPlacement" Value="Right">
                        <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
                        <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
                        <Setter Property="Grid.Column" TargetName="headerPanel" Value="1"/>
                        <Setter Property="Grid.Column" TargetName="contentPanel" Value="0"/>
                        <Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
                        <Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
                        <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
                        <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
                        <Setter Property="Margin" TargetName="headerPanel" Value="0,2,2,2"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </TabControl.Template>
        <TabControl.Resources>
            <DataTemplate x:Key="TabHeader" DataType="TabItem">
                <Border>
                    <Grid>
                        <Grid>
                            <Border x:Name="border" 
                                        CornerRadius="5,5,0,0"
                                        Background="#CC647687"
                                        Opacity="80"/>
                            <Grid x:Name="headerGrid">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Name="Col1" Width="*"></ColumnDefinition>
                                    <ColumnDefinition Name="Col2" Width="22"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <TextBlock x:Name="textInHeader" FontSize="18" Foreground="#FFFFFF" Grid.Column="0" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Header}" Margin="5,0,0,0" HorizontalAlignment="Left"/>
                                <Controls:Tile x:Name="closeBtn" Background="Transparent" Grid.Column="1" Style="{StaticResource ClosableTabButton}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Name}" ToolTip="Close Tab." Click="closeBtn_Click"/>
                            </Grid>
                        </Grid>
                    </Grid>
                </Border>
            </DataTemplate>
        </TabControl.Resources>
    </TabControl>
</Grid>

Это моя сетка внутри UserControl.Я могу предоставить больше информации, если это необходимо.

1 Ответ

0 голосов
/ 15 ноября 2018

Я понял это.Я настраивал содержимое стиля, но это влияло только на последнюю добавленную вкладку.Это потому, что я не настраивал содержимое шаблонов.Что имеет смысл.

<UserControl.Resources>
    <Style BasedOn="{StaticResource {x:Type Controls:Tile}}" TargetType="Controls:Tile" x:Key="ClosableTabButton">
        <Setter Property="Width"
                Value="17"/>
        <Setter Property="Height"
                Value="17"/>
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <iconPacks:PackIconFontAwesome Margin="0,0,0,0" 
                                                       Width="15"
                                                       Height="15"
                                                       Kind="PlusCircleSolid" 
                                                       Rotation="45"
                                                       RenderTransformOrigin="0.5,0.5"
                                                       Foreground="#FFFFFF">
                    </iconPacks:PackIconFontAwesome>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <iconPacks:PackIconFontAwesome Margin="0,0,0,0" 
                                                            Width="15"
                                                            Height="15"
                                                            Kind="PlusCircleSolid" 
                                                            Rotation="45"
                                                            RenderTransformOrigin="0.5,0.5"
                                                            Foreground="#ff0000">
                            </iconPacks:PackIconFontAwesome>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>
...