简体   繁体   English

WPF:Material Design + dragablz tabItem标题样式

[英]WPF :Material Design + dragablz tabItem header style

I am working in WPF with the MaterialDesign Toolkit and Dragablz. 我正在使用MaterialDesign Toolkit和Dragablz在WPF中工作。 I encountered a problem while trying to style a TabablzControl . 我在尝试设置TabablzControl样式时遇到了问题。 I already have style for the windows default TabControl and TabItem header, as shown in the picture: http://i.imgur.com/2anl5rl.png 我已经有了Windows默认TabControlTabItem标题的样式,如图所示: http//i.imgur.com/2anl5rl.png

But when I change the default tabControl to TabablzControl, it turns into this: http://i.imgur.com/bhaaMVy.png 但是当我将默认的tabControl更改为TabablzControl时,它变为: http ://i.imgur.com/bhaaMVy.png

Here are the window.resources: 这是window.resources:

    <Style x:Key="mdTabControl" TargetType="TabControl">
        <Setter Property="TextElement.Foreground" Value="{DynamicResource MaterialDesignBody}"/>
        <Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}"></Setter>
    </Style>
    <Style x:Key="mdTabHeader" TargetType="{x:Type TabItem}">
        <Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}"></Setter>
        <Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Grid>
                        <Border Name="Border"  Margin="1,0,1,0" CornerRadius="3 3 0 0">
                            <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center"
                                              HorizontalAlignment="Center"
                                              ContentSource="Header" Margin="10,2,10,2"
                                              RecognizesAccessKey="True">
                            </ContentPresenter>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Panel.ZIndex" Value="100" />
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource SecondaryAccentBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource SecondaryAccentForegroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="False">
                            <Setter Property="Panel.ZIndex" Value="100" />
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource PrimaryHueMidBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource PrimaryHueMidForegroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource PrimaryHueDarkBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource PrimaryHueDarkForegroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

The error appears when I change the mdTabControl style targetType to: TargetType="dbz:TabablzControl" 我将mdTabControl样式targetType更改为: TargetType="dbz:TabablzControl"时出现错误

I want to keep the style I set to the TabControl , but with the added functionality of the TabablzControl 我想保留我设置为TabControl的样式,但增加了TabablzControl功能

Any help will be appreciated 任何帮助将不胜感激

First thing to note, which is a general WPF characteristic, you are not using style inheritance correctly. 首先要注意的是,这是一般的WPF特性,你没有正确使用样式继承。

As you are using Material Design with Dragablz, if you are restyling the tab control itself, you must inherit from the Material Design style in the Dragablz assembly using BasedOn : 当您使用带有Dragablz的Material Design时,如果要重新设置选项卡控件本身,则必须使用BasedOn继承Dragablz程序集中的Material Design样式:

<Style x:Key="mdTabControl" TargetType="TabControl" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}"> 
    <Setter Property="TextElement.Foreground" Value="{DynamicResource MaterialDesignBody}"/>
    <Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}"></Setter>
</Style>

Again, with the tab header itself, you need to inherit from the relevant style: 再次,使用选项卡标题本身,您需要从相关样式继承:

<Style x:Key="mdTabHeader" TargetType="{x:Type TabItem}" BasedOn="{StaticResource MaterialDesignDragableTabItemStyle}">
    . . .
</Style>

Note, that (depending you your App.xaml setup) you probably need to make sure the correct resource dictionary is included in the same XAML file. 请注意,(根据您的App.xaml设置),您可能需要确保在同一个XAML文件中包含正确的资源字典。 For example a more complete XAML might be: 例如,更完整的XAML可能是:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <Style x:Key="NormalTabItemStyle" TargetType="{x:Type dragablz:DragablzItem}" BasedOn="{StaticResource MaterialDesignDragableTabItemStyle}">
            <Setter Property="Width" Value="280" />
            <Setter Property="Padding" Value="1" />
        </Style>
        . . .
    </ResourceDictionary>                
</Window.Resources>

Finally , as you are changing the TabItem style, you either need to the TabablzCOntrol style the correct style, or you could use it where you actually declare the TabablzControl itself: 最后 ,当您更改TabItem样式时,您需要使用TabablzCOntrol样式正确的样式,或者您可以在实际声明TabablzControl本身的地方使用它:

<dragablz:TabablzControl ItemContainerStyle="{StaticResource mdTabHeader}" />

A good example of all this in action is in the SidePanels project in the demo solution at: https://github.com/ButchersBoy/DragablzSamplez 所有这些实际应用的一个很好的例子是演示解决方案中的SidePanels项目: https//github.com/ButchersBoy/DragablzSamplez

   <Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM